evilben74 Posted February 11, 2015 Share Posted February 11, 2015 Hello, I am currently creating a "dance game" ==> different arrows slide from the top of the window to the bottom, and the player have to press the correct button at the correct time. So, my problem is when the arrows are touching the bottom of the window, I have to kill them, but i didn't know how to do that. I already try to do it with different methods such as the collide ùethod in the update function. :game.physics.arcade.collide(fleche_droite, killeur, creveD);Of course, my sprites have thegame.physics.enable(fleche_bas, Phaser.Physics.ARCADE);and thefleche_haut.body.collideWorldBounds = true;Can you help me ? thanks. Link to comment Share on other sites More sharing options...
John Posted February 11, 2015 Share Posted February 11, 2015 You can set your world bounds using game.world.setBounds(). Then for each sprite you want to kill (example with your fleche_haut sprite): fleche_haut.checkWorldBounds = true; fleche_haut.outOfBoundsKill = true; Or you can do something like: if (fleche_haut.y > game.world.y + game.world.height) fleche_haut.kill(); Or even just (if your world and stage are the same size and you don't move your camera around): if (fleche_haut.y > game.height) fleche_haut.kill(); valueerror 1 Link to comment Share on other sites More sharing options...
Mouseroot Posted February 12, 2015 Share Posted February 12, 2015 You should also be able to check if the sprite is on the bottom using the onFloor methodif(fleche_haut.body.onFloor()) { fleche_haut.kill();} Link to comment Share on other sites More sharing options...
evilben74 Posted February 15, 2015 Author Share Posted February 15, 2015 I tried both methods but none of them work.I think it's due to my "emitter" function, because i call it 4 times per second, and this function generate a random number that i used to make an arrow on the screen... This random number is only between 1 & 4, so it is possible that my scripts cannot identify all of my differents sprites and kill them... Here is my code, and at the moment, I don't know how to make this work properly.function create() { game.physics.startSystem(Phaser.Physics.ARCADE); killeur = game.add.sprite(0, 798, 'killeur'); game.physics.enable(killeur, Phaser.Physics.ARCADE); game.scale.fullScreenScaleMode = Phaser.ScaleManager.EXACT_FIT; game.scale.enterFullScreen.add(onEnterFullScreen, this); game.scale.leaveFullScreen.add(onLeaveFullScreen, this); game.input.onDown.add(gofull, this); //game.stage.backgroundColor = '#00FF00'; game.time.events.repeat(Phaser.Timer.SECOND *.4, 100, createFleche, this); } function createFleche() { /*fleche_haut = game.add.sprite(game.world.randomX, 10, 'fleche_haut'); fleche_bas = game.add.sprite(game.world.randomX, 10,'fleche_bas'); fleche_droite = game.add.sprite(game.world.randomX, 10, 'fleche_droite'); fleche_gauche = game.add.sprite(game.world.randomX, 10, 'fleche_gauche'); */ var x = game.rnd.integerInRange(1, 4); switch(x) { case 1: fleche_haut = game.add.sprite(game.world.randomX, 10, 'fleche_haut'); game.physics.enable(fleche_haut, Phaser.Physics.ARCADE); fleche_haut.body.velocity.y = SPEED; fleche_haut.body.collideWorldBounds = true; fleche_haut.checkWorldBounds=true; fleche_haut.outOfBoundsKill = true; //fleche_haut.body.checkCollision.down = false; //alert("haut"); break; case 2: fleche_bas = game.add.sprite(game.world.randomX, 10,'fleche_bas'); game.physics.enable(fleche_bas, Phaser.Physics.ARCADE); fleche_bas.body.velocity.y = SPEED; fleche_bas.body.collideWorldBounds = true; fleche_bas.checkWorldBounds=true; fleche_bas.outOfBoundsKill = true; //fleche_bas.body.checkCollision.down = false; //alert("bas"); break; case 3: fleche_droite = game.add.sprite(game.world.randomX, 10, 'fleche_droite'); game.physics.enable(fleche_droite, Phaser.Physics.ARCADE); fleche_droite.body.velocity.y = SPEED; fleche_droite.body.collideWorldBounds = true; fleche_droite.checkWorldBounds=true; fleche_droite.outOfBoundsKill = true; //fleche_droite.body.checkCollision.down = false; //alert("droite"); break; case 4: fleche_gauche = game.add.sprite(game.world.randomX, 10, 'fleche_gauche'); game.physics.enable(fleche_gauche, Phaser.Physics.ARCADE); fleche_gauche.body.velocity.y = SPEED; fleche_gauche.body.collideWorldBounds = true; fleche_gauche.checkWorldBounds=true; fleche_gauche.outOfBoundsKill = true; //fleche_gauche.body.checkCollision.down = false; //alert("gauche"); break; } }function update() { /*if(fleche_haut.checkCollision.down || fleche_bas.checkCollision.down || fleche_droite.checkCollision.down || fleche_gauche.checkCollision.down) { this.kill(); }*/ game.physics.arcade.collide(fleche_haut, killeur, creve); game.physics.arcade.collide(fleche_bas, killeur, creveBas); game.physics.arcade.collide(fleche_droite, killeur, creveD); game.physics.arcade.collide(fleche_gauche, killeur, creveG); }Have you some ideas ? Thanks Link to comment Share on other sites More sharing options...
Mouseroot Posted February 16, 2015 Share Posted February 16, 2015 Another idea would be to have a rectangle the width of your screen and add physics to it, then set the collide function to kill the sprite, you could hide the rectangle by settings the alpha to 0. Link to comment Share on other sites More sharing options...
evilben74 Posted February 16, 2015 Author Share Posted February 16, 2015 I tried this too, and in the code i sent just above, this is what i call "killeur", i'ts a transparent png, and it has physics enable Link to comment Share on other sites More sharing options...
Recommended Posts