Hi i'm trying to move a background endlessly, but i have a little problem when i simulate the code.
This is my code
inside the function didMove(to view: SKView) :
for i in 0...1{
let backgroundNEW = SKSpriteNode(imageNamed: "New_Background")
backgroundNEW.size = self.size
backgroundNEW.anchorPoint = CGPoint(x: 0.5 , y: 0)
backgroundNEW.position = CGPoint(x: self.size.width , y: self.size.height
)
backgroundNEW.zPosition = -1
backgroundNEW.name = "test"
addChild(backgroundNEW)
}}
i declare this 3 var
var lastUpdateTime : TimeInterval = 0
var deltaFrameTime : TimeInterval = 0
var amountToMovePerSecond : CGFloat = 200.0
and i call them in my function update ,
override func update(_ currentTime: TimeInterval){
if lastUpdateTime == 0{
lastUpdateTime = currentTime
}
else {
deltaFrameTime = currentTime - lastUpdateTime
lastUpdateTime = currentTime
}
let amountToMoveBackground = amountToMovePerSecond * CGFloat(deltaFrameTime)
self.enumerateChildNodes(withName: "test" )
{
backgroundNEW, _ in
backgroundNEW.position.x -= amountToMoveBackground
if backgroundNEW.position.x < -self.size.height{
backgroundNEW.position.x += self.size.height*2
}
}
}
the thing is i have a grey screen and i dont know why https://gyazo.com/63ce327ce9bc0a14199f411ac187de25
can anyone help me whit this problem please