daniel0514 Posted October 1, 2015 Share Posted October 1, 2015 Hi, I'm currently working on a dance revolution-like game and I've been wondering whats the best way to do this. I'm creating the arrows the player has to press on a group, any time a user press an arrow, if it matches with the one shown on screen, said arrow gets destroyed, the problem is that if two or more arrows come in the same group but the player only press one, all of them gets destroyed. I just want that only the arrow or arrows being pressed gets destroyed. What is the best approach to achieve that? thanks in advance! Link to comment Share on other sites More sharing options...
bruno_ Posted October 1, 2015 Share Posted October 1, 2015 You want to destroy the next arrow, right? Even if there are more than one, the player will have to press them in order, or not? Link to comment Share on other sites More sharing options...
jmp909 Posted October 1, 2015 Share Posted October 1, 2015 sounds like you need to do the detection on the individual sprites in the group, not on the group as a whole or i'm assuming it would be possible to detect an event on the group and then filter it down to the specific item that was pressed. what's your event code? Link to comment Share on other sites More sharing options...
daniel0514 Posted October 1, 2015 Author Share Posted October 1, 2015 I just have an overlap for each of the arrows game.physics.arcade.overlap(this.contactArrowLeft, this.arrows, this.checkArrowsPrecision, null, this); contact arrows are the static arrows showing the moment the player has to press them, this.arrows is an array of groups, each group containing the arrow or arrows generated so that the player can press them. this.creckArrowsPrecision just checks how precise was the user pressing the arrows and gives point based on that, then destroys the group. i have it that way, destroying the whole group, because I haven't been able to find a way to do the children thing i asked about Link to comment Share on other sites More sharing options...
jmp909 Posted October 1, 2015 Share Posted October 1, 2015 this works for me, so I think you may have some other referencing issuegame.physics.arcade.overlap(sprite, group, this.collisionHandler, null, this);collisionHandler (player,enemy) { enemyGroup = enemy.parent; enemy.kill();} Link to comment Share on other sites More sharing options...
jmp909 Posted October 1, 2015 Share Posted October 1, 2015 a bit of extra code to put that in context (i've left out the movement code though) in your example checkArrowsPrecision the second argument should be returning the relevant arrow from the group.. not sure why you've not got direct access to the specific arrow in the group rather than the groupprivate enemiesGroup: Phaser.Groupprivate hero: Phaser.Spritecreate () { // start physics this.game.physics.startSystem(Phaser.Physics.ARCADE); // add hero & enable physics this.hero = game.add.sprite(100,100, 'hero'); this.game.physics.enable(this.hero, Phaser.Physics.ARCADE); // create group with physics this.enemiesGroup = this.game.add.group(); this.enemiesGroup.enableBody = true; this.enemiesGroup.physicsBodyType = Phaser.Physics.ARCADE; // create enemy in the group (just one for now, but normally a loop for several) var enemy:Phaser.Sprite = this.enemiesGroup.create(0,0,'enemy') enemy.body.bounce=0.8; // this works now because the group has enableBody/physicsBodyType}update() { this.game.physics.arcade.collide(this.hero, this.enemiesGroup, this.collisionHandler, null, this);}collisionHandler(player, enemy) { console.log(enemy, enemy.parent) enemy.kill();} Link to comment Share on other sites More sharing options...
Recommended Posts