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.

AppGameKit Classic Chat / 2D Sprite Managment design

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 20th Dec 2015 20:30
Ok, i'm just finished my first AppGameKit game and i must say, i am impressed with the performance.

I ported the game from another basic language and as a consequence my sprite management went like this;

1) Load all images using loadimage() (All images including splash screen, win/lose screen, hud and every image that could possibly be displayed)
2) when i clear the screen i destroy all sprites
3) as i draw the screen i createsprite() from the loaded image and position it. I did not use any of the animation capabilities of the sprite object (although i intend on using them in the future)

Does anyone see any problem using this approach or does anyone have any suggestions as to how better manage images/sprites in an app?
I am very interested to see how people approach sprite management in general or if there are any tips out there
Delta V Software
9
Years of Service
User Offline
Joined: 13th Aug 2015
Location:
Posted: 21st Dec 2015 00:11
Why destroy the sprites each frame? This will reduce performance and animating sprites won't work properly. Just create your sprite at the start of the game and destroy it at the end of the game instead of each loop.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Dec 2015 00:51
so i just make it not visible when i'm not using it?
is there overhead for having a lot of sprites that maybe not used?
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 21st Dec 2015 01:46
Well each sprite will indeed take memory, but unless you have thousands of unused ones, hiding a few and leaving them in memory won't impact anything. So if you know you're going to use the same sprites each level at some point, leave them loaded.
Also, I haven't done a comparison of resource usage between using multiple single sprites and a single animated one, but if you combine your images into a single file and use animate sprite to set the image you want, that could save memory since each sprite you'd create at that point would be a clone. This would be best for a tile map or something where the sprites are all the same size of course.


(above post is by me, forum messed up my account again)

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Dec 2015 02:32
ok' i will try your approach for my next game. thanks for your input
DavidAGK
AGK Developer
10
Years of Service
User Offline
Joined: 1st Jan 2014
Location:
Posted: 22nd Dec 2015 15:15
My platform game has the entire map's worth of tiles (sprites) loaded up for the level. This means thousands of sprites (maps like 300 x 60) all loaded up. AppGameKit seems to handle off-screen sprites very well indeed (i.e. ignoring them in draw calls) so you can have fantastic performance even whilst using thousands of sprites. My understanding is that multiple overlapping sprites on-screen might slow performance but I've not really experienced that either. All in all AppGameKit performance seems pretty awesome with 2D sprites.
Using Tier 1 AppGameKit V2
Started coding with AMOS (Thanks Francois Lionet)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 22nd Dec 2015 16:16
The only other advice I would recommend is the information in the help files. It explains the best ways to work with sprites on screen. (Guides section, not Commands section)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Dec 2015 21:42
thanks guys. i will lookup those guides
Impetus73
13
Years of Service
User Offline
Joined: 28th Aug 2011
Location: Volda, Norway
Posted: 23rd Dec 2015 07:42
I never delete anything. I just position the unused sprites at coordinate -5000,-5000 when they are not used.
----------------
AGK programmer
Did Amiga / AMOS programming in the 90\'s.
nickele upgraded
10
Years of Service
User Offline
Joined: 20th Dec 2013
Location: Birthplace of Democracy
Posted: 23rd Dec 2015 20:29
Apologies if I sound ignorant Impetus73, but are you just positioning the sprites off screen?
Doesn't this affect performance?
Aren't you using SetSpriteVisible or SetSpriteActive commands at all ?
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 24th Dec 2015 09:27
I suspect moving sprites offscreen will have far less impact on performance than deleting and rebuilding the entire sprite-set every frame.
Turning off physics and animation by using SetSpriteActive and SetSpriteVisible would likely further improve performance. Good shout!

Who wants to make a little benchnmark app to test?

V2 T1 (Mostly)
Phone Tap!
Uzmadesign
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th Dec 2015 03:42
Who would delete and reload every frame? Every level sure, but I can't see any instance where someone would even try to do that every frame.

"I like offending people, because I think people who get offended should be offended." - Linus Torvalds
mrradd
9
Years of Service
User Offline
Joined: 24th Feb 2015
Location: CA, USA
Posted: 26th Dec 2015 23:54
Quote: "Who would delete and reload every frame? Every level sure, but I can't see any instance where someone would even try to do that every frame."


This guy.... My first game I thought it would be a good idea to dump sprites--it wasn't.
-mrradd-
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 11th Jan 2016 00:33 Edited at: 11th Jan 2016 00:38
Actually i did it and it works quite well (see the link below). I didn't reload the image, just recreated the sprite from the image. However i will take your advice and keep sprites in memory rather than delete them from now on
https://forum.thegamecreators.com/thread/216042

Login to post a reply

Server time is: 2024-11-17 02:36:57
Your offset time is: 2024-11-17 02:36:57