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 / How to move a sprite that's already positioned somewhere?

Author
Message
Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 6th Jul 2010 22:17
My program is a top-down shooter, that creates a dead body IF the bullet hits the enemy sprite. I use three different images for dead bodies, and i make the program choose one randomly, when the sprite is created. But i need to make those sprites move (change their X and Y coordinates). I only know how to do that with the dbSprite command... but if i use it, the last parameter requires me to insert the what image the command will use for the sprite...
I need a command, that only changes the coordinates of the already existing sprite, instead of creating a new one in the new coordinates (like dbSprite does).

I just love the smell of code in the morning...
Mireben
15
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 6th Jul 2010 23:22
dbSprite does not create a new sprite if it already exists. It's OK to use it to move a sprite. If it's a problem for you that you need to give the image number again, then you can try dbMoveSprite, which needs distance and direction. Or maybe try this, to make sure that the image used for the sprite stays the same:

Wizz
15
Years of Service
User Offline
Joined: 27th Apr 2009
Location:
Posted: 7th Jul 2010 00:47 Edited at: 7th Jul 2010 00:49
Ok.. that last piece of code helped. Thank you!
Still have a problem that i just can't seem to be able to solve on my own. Please take a look at this piece of code and help me out.

It's a code that detects, when an ant(sprite) has been hit by a bullet... and when it was hit, it puts a sprite of a dead body in that position. But in this game i present the movement of the main character by moving the background. So when the player moves, the backround coordinates change by changing the 'x' variable and 'y' variable (not visible in this function, since this is only a part of the much bigger code). So.. i need to move the ant bodies coordinates with +x and +y. The attempt fails: because, when i read the ant coordinates to new variables: 'anbodyX' and 'antbodyY', everytime a new ant is hit, the coordinates change for ALL the bodies at once.. so in the end, all the bodies are in the same place. How do I make them stay, in their primary position?



I just love the smell of code in the morning...
JTK
14
Years of Service
User Offline
Joined: 10th Feb 2010
Location:
Posted: 7th Jul 2010 07:17
Use a struct for each *ANT* and store one instance of that struct for each individual ant you want to deal with in an array (or preferrably an std::vector)...

For example:




Now of course, I'm only trying to imagine what you are trying to do, so you will have to adjust accordingly. In as much, my suggestion is to store each individual *ant's* variables in a struct and store a list of those structs in an array (or std::vector or std::list etc.)...

Hope this helps,

JTK

Login to post a reply

Server time is: 2024-07-04 10:13:12
Your offset time is: 2024-07-04 10:13:12