我想要在所有设备上的同一位置放置形状(矩形和圆形)(例如沿x的40%和y轴的20%)。
这里有一些代码:
class ColourSprite : SKSpriteNode {
var colour: String
var type: String
init(colour: String, categoryBitMask: UInt32, contactTestBitMask: UInt32,
collisionBitMask : UInt32, type : String, point1: array, point2: array, point3: array, point4: array) {
let shape = UIBezierPath()
shape.addLine(to: CGPoint(point1[0], point1[1]))
shape.addLine(to: CGPoint(point2[0], point2[1]))
shape.addLine(to: CGPoint(point3[0], point3[1]))
shape.addLine(to: CGPoint(point4[0], point4[1]))
let texture = SKTexture() //I don't know what to do here
self.colour = colour
self.type = type
super.init(texture: texture, color: UIColor.clear, size: texture.size())
if type == "block" {
self.physicsBody = SKPhysicsBody(rectangleOf: self.size)
}
else {
self.physicsBody = SKPhysicsBody(circleOfRadius: self.size.width/2)
self.isUserInteractionEnabled = true
}
self.physicsBody?.isDynamic = true
self.physicsBody?.categoryBitMask = categoryBitMask
self.physicsBody?.contactTestBitMask = contactTestBitMask
self.physicsBody?.collisionBitMask = collisionBitMask
}
所以我想把所有的点(从gameScene类中以size.height / size.width的形式)传递给我的SKSpriteNode到类,这样它就会将它绘制到屏幕上的正确位置,但我不确定如何使精灵的质地更好,所以它可以保留其物理属性,任何想法?如果这没有任何意义,请告诉我。