xronn Posted February 13, 2014 Share Posted February 13, 2014 Hi, I have a sprite trap that loops very slowly frame 0 its safe but frame 1 it's deadly, can you make a player collide with the same sprite but a different frame? Also am I right in thinking that if you can do this you can make it remove health from the player on a certain frame?thanks Link to comment Share on other sites More sharing options...
ram64 Posted February 13, 2014 Share Posted February 13, 2014 You could add an if-statement in the update loop that checks the frame of the trap sprite and then do a collision:update() {...if(trap.frame == 1) game.physics.collide(trap, player, onTrapHit, null, this);...}function onTrapHit(trap, player) { // do trap damage}In this example you can consider that the trap is deadly on frame 1 (you can test against any other frame or frames). The onTrapHit() is a collision callback in which you do all the damage logic. Link to comment Share on other sites More sharing options...
xronn Posted February 13, 2014 Author Share Posted February 13, 2014 Thank you, extremely useful thanks again for your help, could someone tell me what each parameter does; game.physics.collide(trap, player, onTrapHit, null, this);is this correct trap = sprite variable nameplayer = sprite variable name onTrapHit = call back for the next function null = not surethis = to tell the game object what we refer too? Link to comment Share on other sites More sharing options...
seiyria Posted February 18, 2014 Share Posted February 18, 2014 Adding to this, is there a way to do this with a group? I have a group of sprites that I want to check for collision during a certain frame. It's the same frame for all of them. Link to comment Share on other sites More sharing options...
seiyria Posted February 19, 2014 Share Posted February 19, 2014 I figured this out: had to use the second callback parameter in the collide function to check the frame. Link to comment Share on other sites More sharing options...
xronn Posted February 19, 2014 Author Share Posted February 19, 2014 Seiyria could you share what you wrote for the group collision as I'm trying that now. I tried to just take some health every time the frame was active to see if I'm on the right path, I get no errors but has no effect:if(trapGroup.frame == 2){ hero.health -= 1;} Link to comment Share on other sites More sharing options...
seiyria Posted February 20, 2014 Share Posted February 20, 2014 Sure.this.game.physics.collide(this.game.player.ref, this.fadingBlocks, function(ref, block) { if (ref.body.touching.down) { return _this.game.player.onBlock = true; } };}, function(ref, block) { return block.currentFrame.index === 0; };});This will not work verbatim, it's edited from my compiled coffeescript and likely isn't semantically correct. As for how it works, I make usage of the fourth parameter in the function to determine if the collision can happen with the group "fadingBlocks". Hopefully that helps. Link to comment Share on other sites More sharing options...
Recommended Posts