In my endless runner game, I'm trying to remove an obstacle when it leaves the screen, then create a new one at a set of co-ords off to the right hand side of the screen. It works for the most part. The problem is, when I add a new obstacle, it momentarily flashes into existence at 0,0 (i.e. the bottom left of the scene...). Halp!
function updateObstacle()
if (obstacle) then
if(obstacle.x < -100) then
(obstacle):removeFromParent()
obstacle = nil
end
end
if (obstacle) then
(obstacle):translate(blockSpeed * -1, 0)
end
end
function newObstacle()
if (gameState == gameStates.gameStarted) then
if not (obstacle) then
createObstacle()
end
end
end