Author Topic: FlxVelocity.moveTowardsPoint  (Read 1892 times)

KunoNoOni

  • "Never tell me the odds"
  • Active Member
  • ***
  • Posts: 170
  • Karma: +0/-0
  • Code is Love
    • View Profile
FlxVelocity.moveTowardsPoint
« on: Fri, Jan 6, 2012 »
org.flixel.plugin.photonstorm.FlxVelocity.moveTowardsPoint(source:FlxSprite, target:FlxPoint, speed:int=60, maxTime:int=0):void
Sets the x/y velocity on the source FlxSprite so it will move towards the target coordinates at the speed given (in pixels per second)
If you specify a maxTime then it will adjust the speed (over-writing what you set) so it arrives at the destination in that number of seconds.
Timings are approximate due to the way Flash timers work, and irrespective of SWF frame rate. Allow for a variance of +- 50ms.
The source object doesn't stop moving automatically should it ever reach the destination coordinates.

Parameters:
source The FlxSprite to move
target The FlxPoint coordinates to move the source FlxSprite towards
speed The speed it will move, in pixels per second (default is 60 pixels/sec)
maxTime Time given in milliseconds (1000 = 1 sec). If set the speed is adjusted so the source will arrive at destination in the given number of ms


Does this move the topleft corner or the center of the sprite towards the FlxPoint?


-KunoNoOni

John Hutchinson (Johntron247)

  • Commodore 256
  • Contributor
  • ****
  • Posts: 392
  • Karma: +1/-0
  • I can has lazerz?
    • View Profile
    • Level X Games
Re: FlxVelocity.moveTowardsPoint
« Reply #1 on: Fri, Jan 6, 2012 »
center

KunoNoOni

  • "Never tell me the odds"
  • Active Member
  • ***
  • Posts: 170
  • Karma: +0/-0
  • Code is Love
    • View Profile
Re: FlxVelocity.moveTowardsPoint
« Reply #2 on: Sat, Jan 7, 2012 »
Thank you John, I had a feeling but wanted to make sure :)



-KunoNoOni

John Hutchinson (Johntron247)

  • Commodore 256
  • Contributor
  • ****
  • Posts: 392
  • Karma: +1/-0
  • I can has lazerz?
    • View Profile
    • Level X Games
Re: FlxVelocity.moveTowardsPoint
« Reply #3 on: Sat, Jan 7, 2012 »
Glad to help.  I had to check to be sure.  If you follow some of the functions inside moveTowardsPoint, you will see origin.x / origin.y used.  That's a clear sign that the midpoint is used in the calculation.

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: FlxVelocity.moveTowardsPoint
« Reply #4 on: Mon, Jan 9, 2012 »
As John has already said it uses the sprite origin, which is the center by default, but CAN be changed by you to whatever you need it to be (top left for example)
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

KunoNoOni

  • "Never tell me the odds"
  • Active Member
  • ***
  • Posts: 170
  • Karma: +0/-0
  • Code is Love
    • View Profile
Re: FlxVelocity.moveTowardsPoint
« Reply #5 on: Mon, Jan 9, 2012 »
Would changing it to the top left involve changing the code of the function in the FlxVelocity class or is there a parameter I can use to select top left instead of center?


-KunoNoOni

photonstorm

  • Administrator
  • Key Contributor
  • *****
  • Posts: 1502
  • Karma: +1/-0
    • View Profile
    • Photon Storm
Re: FlxVelocity.moveTowardsPoint
« Reply #6 on: Mon, Jan 9, 2012 »
You'd change the offset property of the sprite in question. Or if you need to keep that the center for some reason, you could modify the function to take a "topLeft" parameter, and then just modify the offset value accordingly.
http://www.photonstorm.com



"Tell me and I will forget, show me and I might remember, involve me and I will understand" - Confucius

KunoNoOni

  • "Never tell me the odds"
  • Active Member
  • ***
  • Posts: 170
  • Karma: +0/-0
  • Code is Love
    • View Profile
Re: FlxVelocity.moveTowardsPoint
« Reply #7 on: Mon, Jan 9, 2012 »
Nice! will try this when I get home.  ;D


-KunoNoOni