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.

Newcomers AppGameKit Corner / Problems with creating and deleting sprites in an array

Author
Message
Webtastic
10
Years of Service
User Offline
Joined: 11th Oct 2013
Location:
Posted: 22nd Dec 2016 16:03
Hello

I'm doing a recreation of Space Invaders as a way to get started with AppGameKit but i'm doing something wrong with handling shots and i suspect it's the part where i destroy them

If i use a variable as a flag to determine if a shot is active everything works fine but if i delete the sprite things start acting up
I could just stick with the active flag but, i don't know, it seems a bit messy moving everything offscreen, then onscreen, setting visibility etc.

What are the best practices regarding this?

I've bought the excellent AppGameKit Tutorial Guide which has helped me a lot but i'm struggling with this part

Could anyone point me towards a tutorial on handling sprites in an array that's relevant to what i'm trying to do?

Thank you
29 games
18
Years of Service
User Offline
Joined: 23rd Nov 2005
Location: not entirely sure
Posted: 22nd Dec 2016 22:40 Edited at: 22nd Dec 2016 22:51
Personally I never delete sprite (or other media) during the game loop. I load everything the game or current level needs then just make sprites active and inactive, visible and invisible as required. From what I understand and have experience, loading media can cause slow down.

I wrote a simple side scrolling shooter that you might find helpful. It's not a tutorial but it might give you some pointers.



I also wrote a simple canon shooting game which you might also find useful.
Hover Car Race Challenge! - available now on Google Play
Invaders of the 29th Dimension - available now on Google Play
Find me on indieDB
GarBenjamin
AGK Developer
7
Years of Service
User Offline
Joined: 30th Nov 2016
Location: USA
Posted: 23rd Dec 2016 01:00
I released the AppGameKit project source for my little game Attack of the Crows not long ago.

It is basically a Space Invaders retro style shmup.

It may be of interest to you. The thread is here. Just scroll down and you will find the link to the game at GameJolt to play in web browser and also the link to download the source.

I just track the state of each object and if inactive if is invisible and also not processed. If an object becomes active (a bullet firing, etc) then its state changes from inactive and it is set to be visible.
TI/994a (BASIC) -> C64 (BASIC/PASCAL/ASM/Others) -> Amiga (AMOS/BLITZ/ASM/C/Gamesmith) -> DOS (C/C++/Allegro) -> Windows (C++/C#/Monkey X/GL Basic/Unity/Others)
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 23rd Dec 2016 03:31 Edited at: 23rd Dec 2016 19:26
Hey,

You could simply use a list to manage your shots.
Creating and deleting sprites in the main loop isn't a speed problem. Just don't load them there

When the shot is outside the screen or hits something, just delete the sprite and the list entry.

Here's what I mean:



PSY
Webtastic
10
Years of Service
User Offline
Joined: 11th Oct 2013
Location:
Posted: 23rd Dec 2016 08:13
Wow, very helpful. Thanks!

So i guess i've stumbled upon sprite pooling which is more efficient in the long run?

I'll stick to active flags then

Thanks again

Login to post a reply

Server time is: 2024-03-29 08:25:10
Your offset time is: 2024-03-29 08:25:10