Just move sprites from point A to B with an event?

0 favourites
  • 13 posts
From the Asset Store
Connect the dots in the correct order and draw happy animals!
  • Making a game where there will be many sprite translations/movement controlled by events...

    Is there an easy way to just place a sprite at some location on-screen then run an event to tell it to go to X,Y coordinates at N speed?

    I couldn't find anything that just does this. With ease-in and out would be even better.

    I don't want to use external plug-ins though. :)

  • I have the same issue - this is my nr.1 desired function.

    I don't think you can do this without someones tween plugin which I am avoiding if I can as they wont be commercially supported.

    I am approximating this with the bullet behavior to send the sprite in the right direction, then stopping it when it goes over a certain coordinate. However, if you make the animation fast, it doesnt seem to stop exactly at the right spot - it seems to overshoot sometimes (which is to be expected). I then pull it back to exactly the right spot.

    I dont know if you can use ease-in with bullet behavior - havent' got that far yet, but I guess you could use the sine behavior at the end?

    Its a shame there is no access to the excellent easing functions in jquery easing plugin.

  • I want this feature too, sometime bullet behavior lerp or 3rd party plugins are not the best choice.

  • Add a couple private variables to the sprite, let's call them GoalX and GoalY.

    + distance(Sprite.X,Sprite.Y,Sprite.GoalX,Sprite.GoalY) > 1

    Sprite: Set position to lerp(Sprite.X,Goal.X,0.1),lerp(Sprite.Y,Goal.Y,0.1)

    ++ (subevent) distance(...same as above...)<1

    Sprite: Set position to Goal.X,Goal.Y

    This basically moves the sprite to goal coordinates, with easing toward goal. See lerp expression in the manual and experiment with it. You can also use this for snapping to position or another object. Following, too.

    The subevent makes sure the sprite sets proper position whenever it is close enough.

    If you want a more smooth move from start to finish, use lerp(StartX,GoalX,Timer),lerp(StartY,GoalY,Timer) as well as a Timer variable which you add dt to (see system expressions, timedelta or deltatime).

    + Sprite.Timer < 1.0

    Sprite: Set position to lerp(StartX,GoalX,Timer),lerp(StartY,GoalY,Timer)

    ++ Sprite.Timer >= 1.0

    Sprite: Set position to GoalX,GoalY

    So, this basically moves the sprite from Start to Goal in one second (Timer = 0 at start and Timer = 1.0 at finish).

    For easing, you want to get a little more creative, you can use the cos for one form of easing at start/end. But that's getting a bit mathy.

  • There is a custom plugin for this, called MoveTo.

  • Or you could use a bit of trigonometry and some system expressions:

    MoveTo.capx (r103.2)

  • Interesting, I didnt now C2 had lerp. Its not in the manual or in the help on expressions so I didnt know it was there - how did the first person find it?

    Mipey - nice example, thanks.

    All this manual maths to move an object from A to B cumon C2, give us a built in MoveTo behavior with easing - you know you want to!

  • nutmix:

    Manual link

  • Nimtrix, doh! I was looking under expressions:

    http://www.scirra.com/manual/78/expressions

    Which is where the in C2 expression help takes you.

    Its a real shame that you cant search the manual for things like this - I can never find what I'm looking for.

  • Hi ,

    is it possible to apply a vehicle Behavior..?

  • If you don't want to use any plugin but still wanted easing, I think it can be done like this

    dl.dropbox.com/u/55358831/tween-without-plugin.capx

    Just implement any penner equation you wanted.

    gizma.com/easing -> some of those equation

    robertpenner.com/easing -> original one

  • Thanks for all your replies people.

    lunarray: that's quite a lot of variables and stuff! :) Thanks for that reference website too.

    nimtrix: seems much simpler.

    I'm going to try both approaches see which one doesn't make my non-math-non-programming brain explode. :)

    Like nutmix said, I'm VERY surprised such a feature hasn't been implemented yet in C2. I mean, it's meant to be used by people with little to no programming/maths skills and for the creation of videogames which involves movement of sprites.

    Anyways, thanks again to all.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Why can't you just use the sine (vertical/horizontal) behavior? Figure out which magnitude and period give you the result you want and set it to active via an event when you want it to; then tell system number of seconds to wait before telling sine to be inactive.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)