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 / Should I delete my menu sprites, or just hide them?

Author
Message
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 28th Feb 2020 10:22 Edited at: 28th Feb 2020 16:01
Somehow I find it most logical to just hide the sprite, instead of recreating them over and over. But hidden sprites still detect collision. What would you say is the smartest approach?

EDIT: Ended up just deleting them. Works fine!
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 28th Feb 2020 18:36
deleting & loading sprites isn't really a problem, deleting and loading large images *can* be slower - with today's hardware it's really not though.
depending how often you want to reuse them it can work just as well to simply move them off screen though if you have a good function for setting them up each time there's not much in it.
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
fubarpk
Retired Moderator
19
Years of Service
User Offline
Joined: 11th Jan 2005
Playing: AGK is my friend
Posted: 28th Feb 2020 18:56
if you plan to set the sprite invisible you also have to set inactive
https://www.appgamekit.com/documentation/Reference/Sprite/SetSpriteActive.htm

fubarpk on Itch...………...https://fubarpk.itch.io/
fubarpk on googleplay..https://play.google.com/store/apps/developer?id=fubarpk
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 28th Feb 2020 22:06
I find creating/deleting sprites constantly to be something I reserve for dynamic gameplay elements... stuff that moves, that needs collision. When it comes to tilemaps, menus, windows and other general static stuff I prefer to keep the sprite alive and just set it to visible when I need to call DrawSprite. And for good measure I also move it off screen and disable it between usage. Since you're probably going to end up hiding the drawing stuff away in a custom function it's no biggie to start and end these drawing functions with SetSpriteVisible, SetSpritePosition, and SetSpriteActive.

Another, perhaps smarter way to look at it, is your intended platform of distribution. If you're going to run your app on a big box, nobody cares. If you're going to run on mobile and tablets, then it's good practice to adopt a programming style that takes battery life into consideration. File access, constantly moving large memory blocks, etc etc... Basically ALL code sucks battery life, but some code is worse. If you need to create and delete sprites on every frame because it's the logical way to structure your code for the app you're making, then so be it. But if you're creating and deleting tons of sprites every frame for no apparent reason, then all you're doing is giving yourself a lot more work in the long run, and an app that kills batteries faster than you can say applealreadykilledmybatterywhentheyreleaseanewversionofiossowhyshouldIcareanyways.
basicFanatic
7
Years of Service
User Offline
Joined: 7th Jun 2017
Location:
Posted: 29th Feb 2020 18:35
Thanks, I'm making a mobile game, so I don't want to waste resources pointlessly. That said, I only recreate 4 sprites when the level starts, so it's not really that big a deal. But I guess moving the sprites one screenwidth left when disabling, and moving one screenlength right when enabling would be just as easy as deleting and recrating. But also SetSpriteActive and SetSpriteVisible, of course.

Here's a screenshot of my game so far:



blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Feb 2020 20:17
Looking good matey!

Login to post a reply

Server time is: 2024-11-22 11:18:40
Your offset time is: 2024-11-22 11:18:40