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.

DarkBASIC Professional Discussion / Storing sprites in arrays?

Author
Message
Aarbear
15
Years of Service
User Offline
Joined: 29th Apr 2011
Location: New York
Posted: 19th May 2012 04:18
Hi,
I need to create sprites during runtime, which isn't difficult. However, I need to be able to access at least 3 different types of sprites individually. For example, let's say I need 10 enemy sprites, 5 dog sprites and an army of turtle sprites. I need to be able to move each group individually, but all of the contents in the group at once.

This would be easy for me in an OOP language like C#, because I would just have a class for each group and store them all in arrays using the NEW keyword. I would then just iterate through the arrays to move all the sprites in one group.

I feel like I just answered my own question, but I can't seem to find a solution for dbPro since it isn't an OOP language and each sprite needs to be numbered.

Thanks for reading,
~Aaron

Str8^
MrValentine
AGK Backer
15
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 19th May 2012 10:29
UDTs...

You might want to look more closely at some of the plugins as they allow you to name objects and now there is a free download to allow naming so try that if it helps...

Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th May 2012 14:51 Edited at: 19th May 2012 15:44
I don't understand why you see this as a problem. You have described what you need to do, which is exactly what you need to do.

Make 3 arrays - enemy(), dog() and turtle()
Then each time you create a new enemy (for example) store it sprite number in the next available enemy 'slot'. then when you want to iterate through your enemy sprites, the actual sprite number is irrelevant.

Wait one - I'll knock up an example. - Done, I hope it helps.



I should point out that when you run this code, it appears to do nothing. You need to press E,D or T to create an Enemy, Dog or Turtle.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 19th May 2012 15:47
Added mailback - Shame you can't do that with an edit.
Scraggle
Moderator
23
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 27th May 2012 16:54
Did that help?

Login to post a reply

Server time is: 2026-07-22 00:35:20
Your offset time is: 2026-07-22 00:35:20