We'll need to move the castle and the silhouettes to create an illusion of the dragon flying. We do this by updating their position after every tick, as shown here:
FairytaleManager.prototype.update = function() { this.updateCastle(); this.updateSilhouette(); };
The update
function will be called from the parent layer (MainMenu
or GameWorld
) on every tick. It is here that you will have to move your castle and the backdrop. The updateCastle
and updateSilhouette
functions are identical, so I will discuss the updateCastle
function only:
FairytaleManager.prototype.updateCastle = function(){ for(var i = 0; i < this.castleSprites.length; ++i) { // first update the position based on the scroll speed var castleSprite = this.castleSprites[i]; castleSprite.setPosition(castleSprite.getPositionX() - MAX_SCROLLING_SPEED, castleSprite.getPositionY()); // check if the sprite has gone completely out of the left edge of the screen if(castleSprite.getPositionX...