El Krusto Posted July 29, 2015 Share Posted July 29, 2015 Hi guys, I want to create a menu screen with flying asteriods, when they leave the screen, they should appear on the opposite side. I thought this should be done automatically when i use Phaser.Physics.ARCADE, but saidly it doesn't work.My menu looks like this:function menu () { var background = game.add.tileSprite(0, 0, viewportWidth, viewportHeight, 'space'); background.autoScroll(5,+10) // random asteroids var asteroids = game.add.group(); asteroids.enableBody = true; asteroids.physicsBodyType = Phaser.Physics.ARCADE; for (var i = 0; i < 15; i++) { var asteroid = asteroids.create(game.world.randomX, game.world.randomY, 'asteroide', 0); var asteroidSize = Math.random() * (1.1 - 0.5) + 0.5; asteroid.scale.set(asteroidSize, asteroidSize); asteroid.body.velocity.x = getRandomArbitrary(-50, 100); asteroid.body.velocity.y = getRandomArbitrary(-50, 100); asteroid.body.angularVelocity = getRandomArbitrary(-50, 50); asteroid.anchor.setTo(0.5, 0.5); //This allows your sprite to collide with the world bounds like they were rigid objects //asteroid.body.collideWorldBounds=true; //asteroid.body.bounce.setTo(1, 1); }}Thx Link to comment Share on other sites More sharing options...
rich Posted July 30, 2015 Share Posted July 30, 2015 In your update function:asteroids.forEach(this.wrapSprite, this);...function wrapSprite(sprite) { world.wrap(sprite, padding);}Where 'padding' is the size of your asteroids (so if they are 32x32 padding should be 32) Link to comment Share on other sites More sharing options...
El Krusto Posted July 30, 2015 Author Share Posted July 30, 2015 This solved it, thank you :-) Link to comment Share on other sites More sharing options...
Recommended Posts