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.

Dark GDK / Effiecency, dbSprite vs dbMoveSprite

Author
Message
egoff12
11
Years of Service
User Offline
Joined: 15th Apr 2013
Location:
Posted: 15th Apr 2013 05:53
Hopefully this is just a simple question, and I'm putting it in the right place. How much less efficient is using dbSprite to deal with movement vs using dbMoveSprite?

i.e.

dbSprite(1, 100, 100, 1);
...
dbSprite(1, 100, 110, 1);

vs.

dbSprite(1, 100, 100, 1);
...
dbMoveSprite(1, 10);
Dum_Bass
11
Years of Service
User Offline
Joined: 20th Mar 2013
Location: Hiding in your closet.
Posted: 30th Apr 2013 13:46 Edited at: 4th May 2013 10:28
When you use dbMoveSprite() by default it will move your sprite either positively or negatively on the Y axis (just up or down). To change this, one must use dbRotateSprite() which can be a pain because that requires reorientating your imported image so you can then rotate it in code to face the direction you want it to without it looking like your sprite is standing on it's head. It is a useful command when you want to move simple projectiles and falling rocks ect. without adding variables and the associated math and dbMoveSprite()will except floating point integers (i.e. dbSpriteMove(spritename, 0.3);

if coded as your example suggests, dbSprite is very innefficient. What you really want is something like this:

//Method 1
int moveX;
int moveY = dbSpriteY (spritename);
moveX += 4;
dbSprite(spritename, moveX, moveY, imagenumber)

//Method 2
int moveX = dbSpritex;
int moveY = dbSpriteY;
dbSprite(spritename, moveX + 4, moveY, imagenumber)


That example will move your sprite from left to right on the screen in a straight line. If you want to change direction you need to write code that changes the values of moveX or moveY. This way gives you far more control over your sprite but at the cost of making you have to think ahead.

Haikus are easy; But sometimes they don’t make sense; Pteredactyl pie
Dum_Bass
11
Years of Service
User Offline
Joined: 20th Mar 2013
Location: Hiding in your closet.
Posted: 30th Apr 2013 23:21 Edited at: 4th May 2013 10:20
Sorry my last post was a little rushed, thus inaccurate.
The following is a better example of how to use the second move method.


and if you wish to implement a jump feature just add two more variables.



Haikus are easy; But sometimes they don’t make sense; Pteredactyl pie
Dum_Bass
11
Years of Service
User Offline
Joined: 20th Mar 2013
Location: Hiding in your closet.
Posted: 1st May 2013 12:55 Edited at: 4th May 2013 10:30
It is important to note that without coding in some boundaries such as collision routines and specifics about how you want your sprite to move, it can do all sorts of unpredictable things (like stop suddenly, or fall through the bottom of the screen). There are many threads throughout these forums that give very specific examples (better than mine). If you haven't already checked this out, you should : http://www.youtube.com/watch?v=cVLyQgzXKUg

Haikus are easy; But sometimes they don’t make sense; Pteredactyl pie

Login to post a reply

Server time is: 2024-11-18 21:39:53
Your offset time is: 2024-11-18 21:39:53