gpt4 book ai didi

swift - 用手指手势移动 Sprite

转载 作者:行者123 更新时间:2023-11-30 11:23:41 24 4
gpt4 key购买 nike

每当我将手指移动到设备屏幕上的任何位置时,我都会尝试移动 Sprite (红点)。下面的代码似乎只在一个看不见的小圆圈内工作,而不是在屏幕的整个区域内工作,这意味着 Sprite 似乎遇到了某种墙壁并且不再继续前进。谁能找出原因吗?

import SpriteKit
import GameplayKit
var positionX = CGFloat()
var positionY = CGFloat()
var newPositionX = CGFloat()
var newPositionY = CGFloat()
var redDotPosition = CGPoint()
var oldPosition = CGPoint()
var newPosition = CGPoint()
class GameScene: SKScene {
var redDot : SKSpriteNode?

var entities = [GKEntity]()
var graphs = [String : GKGraph]()

private var lastUpdateTime : TimeInterval = 0
private var label : SKLabelNode?
private var spinnyNode : SKShapeNode?

override func sceneDidLoad() {

redDot = childNode(withName: "redDot") as? SKSpriteNode
redDot?.texture = SKTexture(imageNamed: "redDot")
redDot?.position = CGPoint(x: frame.midX , y: frame.midX)



}


override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {

for t in touches { self.touchMoved(toPoint: t.location(in: self))


oldPosition = t.previousLocation(in: self)
let oldPositionX = oldPosition.x
let oldPositionY = oldPosition.y

newPositionX = t.location(in: self).x
newPositionY = t.location(in: self).y
deltaX = newPositionX - oldPositionX
deltaY = newPositionY - oldPositionY
redDot?.position = CGPoint(x: redDot!.position.x + deltaX , y: redDot!.position.y + deltaY)


}


}

最佳答案

没关系!

问题在于我不小心将我的 Sprite 锚定到了场景中,因此它的移动量没有超过一定的量。

关于swift - 用手指手势移动 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50996151/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com