Jump to content

Can collide with sprite frame x but not with frame y


xronn
 Share

Recommended Posts

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

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 name
player = sprite variable name 

onTrapHit = call back for the next function 
null = not sure
this = to tell the game object what we refer too? 

Link to comment
Share on other sites

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...