una pregunta sobre spriteKit. Cada vez ejecuto un juego, me aparece el objeto como si el punto de coordenadas de la escena fuera en la mitad de la escena, ósea 0.5. Y he visto la documentación, y dice que el eje de coordenadas de una escena es 0.0, no sé qué hacer. Ayuda, soy principiante.
Basicamente es el fondo de flappy bird y su personaje(porque se encuentran sus componentes con facilidad, y no quería diseñar solo para precticar) en donde si oprimes o arrastras, el ave va a donde pulsaste.
class GameScene: SKScene {
let pajaro = SKSpriteNode(imageNamed: "pajaro")
var lastUpdateTime : TimeInterval = 0
var dt : TimeInterval = 0
let pajaroPixelesPerSecond: CGFloat = 300.0
var velocity = CGPoint.zero
override func didMove(to view: SKView) {
let background = SKSpriteNode(imageNamed: "background")
background.zPosition = -1
addChild(background)
pajaro.position = CGPoint(x: -210, y: 150)
pajaro.xScale = 1/2
pajaro.yScale = 1/2
addChild(pajaro)
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first! as UITouch
let location = touch.location(in: self)
sceneTouched(touchLocation: location)
}
override func update(_ currentTime: TimeInterval) {
if lastUpdateTime > 0 {
dt = currentTime - lastUpdateTime
}else{
dt = 0
}
lastUpdateTime = currentTime
moveSprite(sprite: pajaro, velocity: velocity)
checkBounds()
}
func moveSprite(sprite: SKSpriteNode, velocity: CGPoint){
let amount = CGPoint(x: velocity.x * CGFloat(dt), y: velocity.y * CGFloat(dt))
print("La cantidad que nos movemos \(amount)")
sprite.position = CGPoint(x: sprite.position.x + amount.x, y: sprite.position.y + amount.y)
}
func movePajaroToLocation(location: CGPoint){
let offset = CGPoint(x: location.x - pajaro.position.x, y: location.y - pajaro.position.y)
let offsetlenght = sqrt(Double (offset.x*offset.x + offset.y*offset.y))
let direction = CGPoint(x: offset.x/CGFloat(offsetlenght), y: offset.y/CGFloat(offsetlenght))
velocity = CGPoint(x: direction.x * pajaroPixelesPerSecond, y: direction.y * pajaroPixelesPerSecond)
}
func sceneTouched(touchLocation: CGPoint){
movePajaroToLocation(location: touchLocation)
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
let touch = touches.first! as UITouch
let location = touch.location(in: self)
sceneTouched(touchLocation: location)
}
func checkBounds() {
let bottonLeft = CGPoint.zero
if pajaro.position.x <= bottonLeft.x {
pajaro.position.x = bottonLeft.x
velocity.x = -velocity.x
}
}
Espero que puedan ayudarme(la ultima función es para evitar que el pájaro salga de la pantalla, pero como el punto de coordenadas de la escena está en la mitad, no pasa de la mitad el pájaro), y las demás clases están intactas.