我正在尝试制作一个游戏,用户可以画一条线来获得物理物体,因为这将成为我们主要角色的斜坡。游戏摄像机与主角绑在一起。
如果主要角色在运动中,并且因此导致游戏摄影机运动时,线条似乎绘制得不够快,并导致出现缝隙,导致不可能或主要角色滑过。
如果主角没有动,而我画了一条线,那更好但又不是完美的(见附图)
我的行中有一个帮助文件,它是SKShapenode子类
init(position: CGPoint, previousPosition: CGPoint) {
super.init()
let path = CGMutablePath()
path.move(to: position)
path.addLine(to: previousPosition)
self.path = path
physicsBody = SKPhysicsBody(edgeChainFrom: path)
physicsBody?.isDynamic = false
physicsBody?.friction = 0
physicsBody?.restitution = 0
physicsBody?.categoryBitMask = PhysicsCategory.line
physicsBody?.contactTestBitMask = PhysicsCategory.sleigh
physicsBody?.collisionBitMask = PhysicsCategory.line | PhysicsCategory.sleigh
name = "line"
lineWidth = 10
zPosition = 10
}
我还使用touchesMoved功能画线:
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
for t in touches {
let location = t.location(in: self)
let previousLocation = t.previousLocation(in: self)
let line = Line(position: location, previousPosition: previousLocation)
addChild(line)
}
}
我的问题是,当我的雪橇静止时画一条线时,该线看起来是实心的: pls ignore off center sleigh
但是当雪橇移动时,尽管速度很快,但线条却像与线条并置的那样变成了间隔开的正方形: if i leave my finger on the screen(drawing a line) while sleigh is moving, this happens
我该怎么做才能使线条平滑,以使雪橇滑过线条?