Jump to content
Search Community

kcrik

Members
  • Posts

    3
  • Joined

  • Last visited

kcrik's Achievements

0

Reputation

  1. kcrik

    Box2D with TweenLite

    I just tried : TweenLite.set(g_ball.sprite.body.GetPosition(), {x:x, y:g_ball.sprite.body.GetPosition().y}); But it's the same result. So will stay with the solution I found Thanks for the help though !
  2. kcrik

    Box2D with TweenLite

    Thanks for the fast answer !! I have managed to fix it in the end. I am not too sure why, but after the tween is killed, the object is put back at its original position. I suspect that the tween does its job every frame on the object at setting x directly. However if you do that, it works on the frame you do it, but that's it. I tried by forcing the setting of the position doing : g_ball.sprite.body.GetPosition().x = 2 I can see the ball blink at the position x = 2, but just for 1 frame. So my belief is that TweenLite updates each frame the x position that way. Because it does it every frame, it seemingly work, when in reality the physic engine will try to put the coordinates back to its origin. So my solution is : function onMouseDown(event) { g_tween.kill(); g_ball.sprite.body.SetPosition(new box2d.b2Vec2(x, g_ball.sprite.body.GetPosition().y)) g_world.SetGravity(new box2d.b2Vec2(0, 30)) } This way I set the position in the physic world on the latest coordinates set by The tween, which are correct I think box2D isn't too great with TweenLite. Any way, it might help some people who have the same issue
  3. Hello, It's my first time posting here, so apology if it's not done correctly. I have a problem. I have a game where I interpolate, via TweenLite, the position of a sprite. I interpolate the position of its box2D body to be precise. Even though the tweening in itself works fine, once I kill the tween, it puts back my object at its initial position and I can't figure out why. I am sure it's something stupid, like a param to pass, but can't find it in the doc. Maybe there are issues when tweening with box2D ? Thanks for your help. Code: var fromX = ((BALL_SIZE * BALL_SCALE) / SCALE) var toX = ((STAGE_WIDTH - (BALL_SIZE * BALL_SCALE)) / SCALE) g_tween = TweenLite.fromTo(g_ball.sprite.body.GetPosition(), 3.0, {x:fromX}, {x:toX, ease:Linear.easeNone, onComplete:onTweenComplete, onReverseComplete:onReverseComplete}); function onTweenComplete() { g_tween.reverse() } function onReverseComplete() { g_tween.play() } // *********** // Callback when user click on the screen // The game release the ball if it hasn't been released yet // *********** function onMouseDown(event) { //var newBall = new Ball() //g_sprites.push(newBall) var x = g_ball.sprite.body.GetPosition().x console.log("x: " + x) g_tween.kill() g_ball.sprite.body.GetPosition().x = x console.log("g_ball.sprite.body.GetPosition().x: " + g_ball.sprite.body.GetPosition().x) g_world.SetGravity(new box2d.b2Vec2(0, 30)) }
×
×
  • Create New...