Import Sprites in main()

SGDK only sub forum

Moderator: Stef

Post Reply
Spaced2
Newbie
Posts: 1
Joined: Thu Sep 26, 2019 6:16 pm

Import Sprites in main()

Post by Spaced2 » Fri Dec 27, 2019 12:32 pm

Hi, my first question. I’m still a learner programmer so hope I can get my questions across. Using SGDK examples I’ve got the starting of my game but I’m importing quite large sprites and must be breaking sprite limits as I cannot define them all in main() and have them appear.

I’m defining in rescomp and importing using SPR_addSprite to add them. At the start I’m hiding them off-screen and only moving them onscreen when needed using SPR_setPosition.

I cannot add all of them in main() as then some are not appearing when needed. Is there a way to only add sprites when needed but out of the main loop?
Cheers :D

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Re: Import Sprites in main()

Post by Stef » Fri Jan 03, 2020 10:14 am

You have indeed some limitations about the number of sprite you can use. The hardware itself is limited to 80 sprites max (H40 mode) so the sprite engine limit to 80 sprites max too. You cannot what you're doing : adding all sprites (using addSprite) for a level then hiding some of them until they become active, you will quickly raise the sprite limit doing that if your level is big. You need to handle add/release sprite on the flow while you're progressing in the level, it's more complex as you need to carefully recycle sprites but that is the only way to handle large level with many enemies.

Post Reply