嗨,我正在制作游戏,需要在底部确定一个峰值,我决定通过UIView和碰撞来实现。我正在快速编码。
我目前有一个广场:
//Object Setup
let square = UIView(frame: CGRect(x:100, y:100, width: 100, height: 100))
square.backgroundColor = UIColor.purpleColor()
view.addSubview(square)
我想要一个三角形,我有一个可以用于三角形的图像,但是该图像是正方形的,因此可以肯定的是,碰撞将是当它接触到图像边界而不是实际的三角形边界时,请咨询如何处理图像或我怎么变得方形。
谢谢
亚历克斯
这里有教程:
http://jamesonquave.com/blog/drawing-custom-views-with-swift-andrew-vanwagoner/
用这样的代码:
func drawPlayPathTo(context: CGContextRef, boundedBy rect: CGRect) {
CGContextSetFillColorWithColor(context, UIColor.blackColor().CGColor)
CGContextMoveToPoint(context, rect.width / 4, rect.height / 4)
CGContextAddLineToPoint(context, rect.width * 3 / 4, rect.height / 2)
CGContextAddLineToPoint(context, rect.width / 4, rect.height * 3 / 4)
CGContextAddLineToPoint(context, rect.width / 4, rect.height / 4)
CGContextFillPath(context)
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句