espace Posted September 27, 2016 Share Posted September 27, 2016 hi, i think that this snippet work good but it's interesting if you you could give me some advice or optimization that I would not have thought at the base the principle is an object (sprite1) who is falling and some other object (table) slow down his fall. https://jsfiddle.net/espace3d/a13v8r8b/ thanks var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'phaser-example', { preload: preload,create: create, update: update, render: render }); var table var sprite1 function preload() { game.load.image('circle', 'https://s13.postimg.org/xjhlzmiev/disc_png.png'); game.load.image('rect', 'http://s10.postimg.org/6fa6mgrd5/motif.jpg'); } function create() { game.physics.startSystem(Phaser.Physics.ARCADE); sprite1=game.add.sprite(400, 300, 'rect'); sprite1.anchor.x=.5 sprite1.anchor.y=.5 sprite1.width=100 sprite1.height=100 sprite1.alpha=1 game.physics.enable(sprite1, Phaser.Physics.ARCADE); table=[] for (var j=0; j < 10 ;j++) { table[j] = game.add.sprite(0, 0, 'rect') table[j].width = 400 table[j].height = 1 table[j].x = 200 table[j].y = game.rnd.between(400,500) game.physics.enable(table[j], Phaser.Physics.ARCADE); table[j].body.immovable = true; } } function update() { sprite1.body.velocity.y = 100 for (var j=0; j < table.length ;j++) { game.physics.arcade.collide(sprite1, table[j],collision,null,this); } } function collision(obj1,obj2){ game.time.events.add(150,() => destroyTable(obj2),this) } function destroyTable(obj2){ obj2.body.enable=false obj2.visible=false } function render() { } Link to comment Share on other sites More sharing options...
drhayes Posted September 27, 2016 Share Posted September 27, 2016 You could stick the tables you create in a group then check collision against that group instead. It's still basically a for-loop under the covers, but then you get other convenience methods like getFirstAlive, etc. Link to comment Share on other sites More sharing options...
espace Posted September 28, 2016 Author Share Posted September 28, 2016 hi drhayes, i folllow your advice and start this but it seems that the group is undefined and the collision don't work...if i have time i search a little more about this https://jsfiddle.net/espace3d/avmy0qto/ Link to comment Share on other sites More sharing options...
Recommended Posts