Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [SOLVED] Best way for move sprites

Author
Message
Rocco Sette
6
Years of Service
User Offline
Joined: 2nd Aug 2017
Location:
Posted: 11th Oct 2018 07:33
Good morning, everyone,

I am currently working on a project that requires moving sprites on a map.
What I currently use to move them are tween with TweenLinear and two-dimensional tables to see if the next move can be made or not.

However, I would like to be able to use this two-dimensional table but move my sprites more finely.
Would it be better to use SetSpritePosition or would it be better to stay on tween?
Does anyone have any leads to advise me?

Thank you.

The author of this post has marked a post as an answer.

Go to answer

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 11th Oct 2018 13:37
This post has been marked by the post author as the answer.
When you say a 2D table, do you mean like a grid and checking the next square to see if it's open to walk to?

I've never used the tween commands before so I'd say position the sprite manually.

dx and dy are normalized direction vector pointing the sprite towards its destination. If your sprite can only move along the axis, then:
right => dx=1,dy=0
left => dx=-1, dy=0
up => dx=0, dy=-1
down = dx=0, dy=1

If it can move diagonally, then determine the angle to the target and calculate the vector like this:

dx = cos(angle)
dy = sin(angle)

speed is how fast you want to move (obviously).

When you're ready to make the sprite move, set the flag spriteMoving. Don't forget to switch the flag off once the sprite reaches the intended target.

Tiled TMX Importer V.2
XML Parser V.2
Base64 Encoder/Decoder
Purple Token - Free online hi-score database
Legend of Zelda

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds

Login to post a reply

Server time is: 2024-04-20 12:56:41
Your offset time is: 2024-04-20 12:56:41