2D animation strip - drawing lots of instances
BlitzMax Forums/BlitzMax Beginners Area/2D animation strip - drawing lots of instances
| ||
With this being my first game, and having no object-oriented experience whatsoever, I've come across a small problem I'd like an opinion on... When one of the 4 players hits a wall, I draw an explosion - LoadAnimImage strip of 32 frames I have a type, Texplosion containing fields such as x,y,frame,flag_active I create an array to hold the 4 player explosions then in my main loop I loop thru each player and check if explosion[x]flag_active is true. If it is I draw the eplosion. Trouble is, each player can trigger an unknown quantity of eplosions So my question is, instead of using an array (which is fine for a KNOWN quantity of explosions) is there an alternative way to draw as many explosions as I need ? |
| ||
I've some across this example: http://www.2dgamecreators.com/tutorials/gameprogramming/basics/F5%20-%20Adding%20Missiles.html Should I be using a LIST of "game objects" from which I LISTADD and LISTREMOVE ? That way every time I need to draw an explosion is gets added the list of "game objects" to draw ? Its the first time I've actually come across METHODS and LISTS before! D'oH! |
| ||
Lists are pretty good for being able to add and remove stuff efficiently, so yes. |
| ||
Yep. Use a for eachin loop to go through every explosion in the list. Draw it and update its frame. If it's reached the end of its animation then remove it from the list. |
| ||
ah great - thanks for that confirmation I'll get on it Now I've discovered methods and lists, they seem pretty cool - I think I'll have to go back through my code and make the appropriate adjustments! |
| ||
I have been doing extensive testing the past few weeks, trying to decide which avenue to take. I'm used to using arrays for all of my game objects, and based on my tests arrays are indeed faster. Especially if you don't have to remove anything, just initialize the array with as many objects as you'll need, and then "re-use" objects as needed. Works fine and is probably the fastest way you can do it, at least with my own tests compared to using a TList. However.... with that said I am using TList's for pretty much all of my game objects now. The ease of use, on a broad, general scale, was the deciding factor for me. The only thing I've noticed that happens is a slight performance stutter, once in a great while. I "think" this is the internal garbage collection due to removed items. ? |
| ||
Thanks MGE I was happy with arrays, but you must admit, its not as ELEGANT as TLists, now I've seen the sample code I mentioned in my link. For my game, the slight performance hit you mention won't be an issue - I'm only running 800x600 fullscreen with a max of 8 sprites (although I'm planning to increase this!). Its just a simple retro-remake of an 80's game. |
| ||
"Its just a simple retro-remake of an 80's game." Ok, now you've peaked my interest. :) 800x600 for an arcade game is still actually a fairly high resolution. Considering some of those retro classics were 320x200 or less. lol.. |
| ||
For tight (performance) loops, arrays will always be better than TLists. The trick is to find the right balance :-) |
| ||
MGE, You're right, 800x600 is higher than the original game's 512x384, but hey, that's what's so appealing about a 2D retro remake - you can let loose with tons of sprites , sounds and effects, alpha transparencies, etc... I'm loving it, but not having programmed games before, its pretty new. Next on the list TO DO is collision detection between the spries. I want to have 4 collision boxes PER SPRITE - so the sprite can react accordingly, so I'll be checking through the code archives for any scraps. |
| ||
I used to use arrays, a pool of the correct size. But now I use lists for ease of coding. |
| ||
Thanks Grey |