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 / How to add a speed variable to the Moving sprites example

Author
Message
Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 3rd May 2012 23:46
Hi
This is really basic stuff but I have used the "Moving sprites" example in the docs to make a selection of my sprites move at different speed to their destination.
Here is the code from the docs:



If I add more than 2 to in the "move = move +2" command - some of the sprites will not land at their exact destination.
Since the example uses float variables - how can I make sure the sprites land at their destination?
I have tried to use "round" or "floor" - but with no luck...

I'm a donut....
Would you help a dount?
xCept
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 4th May 2012 03:35
The easiest solution in this example would be to set newX# and newY# to the actual destination coords as soon as move is not less than the total distance.

Timshark
16
Years of Service
User Offline
Joined: 30th Jun 2007
Location: Oslo, Norway
Posted: 4th May 2012 04:37
Thank you with a glass of champagne - that did it...

I'm still unsure about the use of float variables....is this used for precision?
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 4th May 2012 10:32
Quote: "I'm still unsure about the use of float variables....is this used for precision?"

Yes. Using floats is generally more accurate but not always necessary. I tend to use a float for position, angle and scale.

If you are using physics sprites you can set the velocity or add forces to move sprites too but I suggest getting to grips with the basics first.

Login to post a reply

Server time is: 2024-05-02 08:05:38
Your offset time is: 2024-05-02 08:05:38