hugo Posted April 15, 2014 Share Posted April 15, 2014 hello! i'm trying to animate a group of clouds in the skyand i want to make it loop how can i do this here's my code so far <!DOCTYPE html><html> <head> <meta charset="utf-8" /> <title>clouds</title> <script type="text/javascript" src="phaser.min.js"></script></head><body> <div id="gameContainer"> </div> <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.AUTO, 'phaser-example', { preload: preload, create: create, update: update }); function preload() { game.load.image('background', 'assets/background.png'); game.load.image('plane', 'assets/plane.png'); game.load.image('cloud', 'assets/cloud.png'); } var plane; var clouds; function create() { game.add.image(0, 0, 'background'); game.physics.startSystem(Phaser.Physics.ARCADE); game.physics.arcade.gravity.y = 10; plane = game.add.sprite(100, 96, 'plane'); game.physics.enable(plane, Phaser.Physics.ARCADE); clouds = game.add.group(); for (var i = 0; i < 60; i++) { sprite = clouds.create(120 * i, game.world.randomY, 'cloud'); game.physics.enable(sprite, Phaser.Physics.ARCADE); sprite.body.allowGravity = false; sprite.body.velocity.x = -150; } } function update () { if (plane.outOfBoundsKill == true) game.state.restart(); } function restart () { } </script></body></html> Link to comment Share on other sites More sharing options...
rich Posted April 15, 2014 Share Posted April 15, 2014 Check if the cloud has left the side of the screen and re-position it on the opposite side? CanDbas 1 Link to comment Share on other sites More sharing options...
hugo Posted April 16, 2014 Author Share Posted April 16, 2014 Check if the cloud has left the side of the screen and re-position it on the opposite side?thanks richdo you know an example of this? Link to comment Share on other sites More sharing options...
Recommended Posts