Jump to content

Tweens and collisions (Phaser 1.0)


bunnyhero
 Share

Recommended Posts

hi! i'm trying out phaser for the first time (using 1.00TS083) and loving it so far.

 

i am making a simple game where some sprites (cars) are being moved with tweens. the tweened cars have 'immovable' set to true (so their motion isn't affected by collisions), and the player sprite is being moved with the keyboard (setting its velocity based on what keys are down, like in many of the test examples). i am calling myGame.collide(cars, player) in the update() callback.

 

when i try to move the player into a car, the player stops, as expected. but if a car moves into the player, the car and the player end up overlapping.

 

if i move the car sprites using velocity, rather than tweens, then the cars push the player out of the way, as expected.

 

any suggestions? is this a bug, or expected behaviour? or maybe i'm doing something wrong?

 

thanks for any help!

 

Link to comment
Share on other sites

Honestly I'm surprised this even works in the 1.00TS083 branch as I had velocity and collide disabled in there :) I wonder if you're actually using 0.95?

 

Either way when you tween a sprite the collision response will depend on what value you tweened. For example if you are tweening the sprite x/y values directly then its entirely possible you end up translating the sprite directly into another one and the collision code never picks this up, because it checks velocity and position and then separates based on those values, but tweening them directly would break the separation. If you tween a sprite velocity however then collision should still work fine. Again this is only in the 0.95 (master) branch right now I'm afraid.

Link to comment
Share on other sites

  • 2 months later...

I have the following code:

 

var sprite1, sprite2;
 
function create() {
     game.stage.backgroundColor = '#cecece';
 
     sprite1 = game.add.sprite(50,200,'bola1')
     sprite2 = game.add.sprite(700,200,'bola2');
 
     var bounce1 = game.add.tween(sprite1);
     bounce1.to({x: 700}, 1000+Math.random()*3000, Phaser.Easing.Bounce.In);
     bounce1.start();
 
     var bounce2 = game.add.tween(sprite2);
     bounce2.to({x: 50}, 1000+Math.random()*3000, Phaser.Easing.Bounce.In);
     bounce2.start();
 
}
 
function update() {
    game.physics.collide(sprite1,sprite2);
}
 
But the Sprites never collides =(

If I use accelerateToObject or to some XY, they collides as I wish. The version of Phaser is 1.1.
 
Any ideias?
Link to comment
Share on other sites

This is correct. You can't separate something that has no velocity (well you can, but it's impossible to know from which direction it came). We're looking at implementing a delta value on the sprite itself, not just the body, which would give us this information - but there is no time frame for this. For now I would suggest you tween the velocity directly or use a different method for collision (a simple rectangle check perhaps?)

Link to comment
Share on other sites

Ok, guys. My intention is make a rocket that shot projectiles to a direction (an angle) and, on the moment that it shots, he acts like is receiving a fast recoil from by the shot. Begining fast to slow. So, I think that must use accelerateTo functions. 

 

If you know other way, please tell me. Thank you!

Link to comment
Share on other sites

  • 11 months later...

var sprite = mygroup_for_collide.create (100, 100, "dyamond");

sprite.enableBody = true;

sprite.body.collideWorldBounds = true;

sprite.body.gravity.y = -750;

var tween = game.add.tween(sprite).to({ x: 600 }, 2000, Phaser.Easing.Linear.None)

.to({ y: 300 }, 1000, Phaser.Easing.Linear.None)

.to({ x: 100 }, 2000, Phaser.Easing.Linear.None)

.to({ y: 100 }, 1000, Phaser.Easing.Linear.None)

.loop()

.start();

hi,

this is an old post, but I have got the same problem

can I make one collision between a tween ( inside my group ) and a player with the new versions of phaser ?

thks for all, and thks for phaser
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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