Jump to content

Rotate an image according to the Tween


Bihos
 Share

Recommended Posts

Hello, first of all forgive me for my English, it is very bad.
I'm trying to rotate an Sprite based on the Tween.
I add a tween for each point of the road as seen here:
  var tweens = [];
  for(var i = 1; i < path.length; i++){
      var ex = path[i].x;
      var ey = path[i].y;
      
      if (i == path.length-1)
      {
        tweens.push({
          targets: soldier,
          x: {value: ex*64+32, duration: 600},
          y: {value: ey*64+32, duration: 600},
          onComplete: onCompleteHandlerFinal
        });
      }

      else
      {
        tweens.push({
          targets: soldier,
          x: {value: ex*64+32, duration: 600},
          y: {value: ey*64+32, duration: 600},
          onComplete: onCompleteHandler,
          onStart: onStartHandler
        });
      }
      
  }
  scene.tweens.timeline({
    tweens: tweens
  });
 
and I have a function that rotates my object (Spirte), which receives the points x and y where it should point:
rotate (to_x, to_y, delta){
  let myPoint = new Phaser.Geom.Point(this.x+32,this.y+32);
  let pointTo = new Phaser.Geom.Point(to_x+32, to_y+32);
  this.rotation = Phaser.Math.Angle.BetweenPoints(myPoint, pointTo) + delta;
}
my idea is to rotate the image in the onStartHandler method, but I can not get the coordinates of the point where it is going.
function onStartHandler (tween, targets, gameObject)
{
  console.log(targets[0].x);
  console.log(tween.anyMethod()); //I need a method that returns the x coordinate
                                  //where the sprite goes in this tween
}

 

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...