cap Posted February 4, 2014 Share Posted February 4, 2014 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 More sharing options...
Alvin Posted February 4, 2014 Share Posted February 4, 2014 Hello,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 More sharing options...
cap Posted February 5, 2014 Author Share Posted February 5, 2014 I tried the dev branch (github.com/photonstorm/phaser/tree/dev/build) with the same create and update callbacks. It seems nothing has changed. "Hit" doesn't work. Link to comment Share on other sites More sharing options...
Alvin Posted February 5, 2014 Share Posted February 5, 2014 Ooops sorry I didn't see the little mistake in your code, all sprites must have "sprite.inputEnabled = true" if you want to be able to use "enableDrag" Link to comment Share on other sites More sharing options...
cap Posted February 5, 2014 Author Share Posted February 5, 2014 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 More sharing options...
cap Posted February 7, 2014 Author Share Posted February 7, 2014 Hi, I tried 1.1.4 released yesterday. The "hit" is somewhat working but buggy. When dragging sprite is "slow" the second sprite starts movement, otherwise it doesn't. Link to comment Share on other sites More sharing options...
Recommended Posts