Jump to content

Hit by a draggable sprite.


Recommended Posts

Let's say there are two sprites and one of them is draggable. How to implement "impact" when the draggable  sprite hits the second one, such that the second sprites starts moving with the speed of the draggable one. Here is what I tried:

create() {    this.cat = this.game.add.sprite(...);    this.cat.body.bounce.setTo(0.5, 0.5);    this.cat.input.enableDrag(false, true, false, 255);    this.dog = this.game.add.sprite(....);    this.dog.body.bounce.setTo(0.5, 0.5);}
update() {
    game.physics.collide(this.cat, this.dog);

It seems this code does  nothing. Could you help please?

Link to comment
Share on other sites


The behaviour you're encountering is intended, at the moment and as of Phaser 1.1.3, collision against a draggable sprite is impossible.


You have two choices, implement the collision yourself, or wait for 1.1.4 to be released, with the brand-new physics system that Richard implemented, it will be possible, you can check it out in the dev branch, but be careful because it's not entirely ready yet.

Link to comment
Share on other sites

Thanks a lot for your help!!! 

Still doesn't work... That's my code:

 create() {        this.input.maxPointers = 1;        this.stage.disableVisibilityChange = true;        this.cat = this.game.add.sprite(50, 50, 'cat');        this.cat.anchor.setTo(0.5, 0.5);        this.cat.body.bounce.setTo(0.5, 0.5);                this.cat.inputEnabled = true;        this.cat.input.enableDrag(false, true, false, 255);        this.cat.inputEnabled = true;        this.dog = this.game.add.sprite(200, 200, 'dog');        this.dog.anchor.setTo(0.5, 0.5);        this.dog.body.velocity.x = this.dog.body.velocity.y = 1;         this.dog.body.bounce.setTo(0.5, 0.5);                this.dog.inputEnabled = true;    }    update() {        this.game.physics.collide(this.cat, this.dog);    }
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.

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.


  • Recently Browsing   0 members

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