nana Posted June 6, 2016 Share Posted June 6, 2016 Hello, i'm working on a simple game that include falling objects like bricks, the thing that is confusing me is what should i consider the bricks! spritesheet or Platform group?? and whats the best function should i use for automatic fall down bricks ? Thank you! Link to comment Share on other sites More sharing options...
Taggrin Posted June 6, 2016 Share Posted June 6, 2016 Whether you want to use a spritesheet depends on your needs. If you have just a single image you don't need to. If you have multiple variations or an animated texture then it is a good choice. As for the bricks falling down, you can just apply gravity to the object with arcade physics: create: function () { //Enable arcade physics this.physics.startSystem(Phaser.Physics.ARCADE); //Spawn brick brick = this.add.sprite(100, 100, 'bricksprite'); this.physics.enable(brick,Phaser.Physics.ARCADE); //Set gravity brick.body.gravity.y = 50; } More info here: http://phaser.io/examples/v2/arcade-physics/gravity Link to comment Share on other sites More sharing options...
nana Posted June 7, 2016 Author Share Posted June 7, 2016 function create(){ .... // now the rocks rocks = game.add.group(); rocks.enableBody = true; .... } function update(){ game.physics.arcade.collide(player, platforms); game.physics.arcade.collide(rocks, platforms); game.physics.arcade.collide(player, rocks); game.physics.arcade.collide(rocks, rocks); j++; if (j === update_interval) { fallingrocks(1); update_interval = Math.floor(Math.random() * 20) * 60; // 0 - 20sec @ 60fps j = 0; .... } function fallingrocks(i){ if (i==1){ rock = rocks.create(Math.floor(Math.random() * 45), 0, 'rock1'); rock.body.gravity.y = 200; rock.body.bounce.y = 0.4;} else if (i==2) { rock = rocks.create(Math.floor(Math.random() * 45), 0, 'rock2'); rock.body.gravity.y = 150; rock.body.bounce.y = 0.3;} else if (i==3) { rock = rocks.create(Math.floor(Math.random() * 45), 0, 'rock3'); rock.body.gravity.y = 100; rock.body.bounce.y = 0.2;}else { rock = rocks.create(Math.floor(Math.random() * 45), 0, 'rock4'); rock.body.gravity.y = 50; rock.body.bounce.y = 0.1; } rock.body.immovable = true; rock.body.collideWorldBounds = true; } Actualy i used Group! but the collision between the rocks and the Platform and between the rocks and each other! thats the code! Link to comment Share on other sites More sharing options...
Recommended Posts