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 / SetSpriteVisible or DeleteSprite?

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 11th Jan 2015 21:06
Hi.

I want make a little game and want use SetSpriteVisible() for show or hide Sprite instead DeleteSprite(). I test it and work but before use it for all sprite I have a question:

I think if sprite set to invisible don't use memory and Proccessor.I need know Is this true?and can use it instead DeleteSprite()?

Thanks.
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 11th Jan 2015 22:03 Edited at: 11th Jan 2015 22:12
//Not sure about the memory or processor strain, BUT...
If you are not going to use it again, then delete it.
If you are going to use it again, then use invisibility.
// It is up to you, but that is what I would do.

janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 11th Jan 2015 22:05 Edited at: 11th Jan 2015 22:08
Hi,

I think SetSpriteVisible just sets the Visibility of a sprite I can not say if it don't use any gpu processor time but im sure it will save a bit somwhere.
Annyway it will use memory the whole time.

But you can use SetSpriteActive() wich then should save some gpu/cpu time.

But to make sure it doesn't use anything just delete it..
Another way is to use DrawSprite()
Just create ONE sprite and set it's position then draw it and set it to the next position where u need another sprite of it's kind and so on..

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 11th Jan 2015 22:09 Edited at: 12th Jan 2015 16:33
Think about it for three seconds! Yet another pointless post.

There's a cat in my room.
The cat takes up space on my floor.
The lights go out.
The cat is invisible.
The cat still takes up space on my floor.

I kill the cat and throw it out of the window.
The cat takes up no space on my floor.

The garbage collector takes the cat away.

[Mod Edit]What's with the vendetta? The only pointless question is not asking the question. Experience always trumps a help file. I'm tired and embarrassed of experienced users "attacking" newcomers to AppGameKit or any language. Another way to have gone about this would to have just said, "Here's a metaphor example"

Onwards and sometimes upwards
janbo
16
Years of Service
User Offline
Joined: 10th Nov 2008
Location: Germany
Posted: 11th Jan 2015 22:22 Edited at: 11th Jan 2015 22:23
lol

You nailed it!

So you are the garbage collector.. good to know..

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 11th Jan 2015 23:02
JimHawkins, what do you have against cats?

But he is right (about sprites). Unless deleted, the sprite does take up resources, even when hidden. It takes up less if set inactive using the SetSpriteActive command as suggested by janbo.

It really does depend on how much you need the sprite later.

Cheers,
Ancient Lady
Conjured Entertainment
AGK Developer
19
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 11th Jan 2015 23:50 Edited at: 12th Jan 2015 00:03
lol
It sounds like I should be deleting those sprites after all. Or, at least I should be using the SetSpriteActive. My games so far have been simple enough that it has not been a problem for me, but I guess I better get used to doing it their way to get in the habit of doing it in a way that will avoid running into problems when they are not so simple.
However, after the cat comment, I think I will opt for the SetSpriteActive instead of deleting them.

Poor kitty.

JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 12th Jan 2015 00:01
AL - I have nothing against apart from those that come and crap in my garden!

There's a long scientific use of cats in thought experiments!

Onwards and sometimes upwards
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Jan 2015 02:13
Behdad: A far better post would have been:

Quote: "Hi.

I want make a little game and want use SetSpriteVisible() for show or hide Sprite instead DeleteSprite(). I test it and work but before use it for all sprite I wrote a little test application based on some useful examples I found such as the benchmark example. Created 1000 sprites, and performed benchmarks on visible, hidden, deleted, active etc. and here is the code and my results! What results do you get!?"


It's such a simple thing to test for, there was no need to ask the question in the first place! - I'm kind of tired and grouchy, so time for a coffee! Now, can anyone tell me how to make coffee? Show me the codes!



unlikely
12
Years of Service
User Offline
Joined: 5th Mar 2012
Location: Ohio, USA
Posted: 12th Jan 2015 16:22
If you were going to be creating and destroying a bunch of sprites in a short time, such as a custom particle system, I would suggest using a pool of sprites and using visible / active to control and reuse. Otherwise you may be generating a lot of garbage, which will have a negative performance impact.

Otherwise, if memory usage is important, or you are not continually creating / destroying sprites of the same type, I would delete them when you are finished with them.

This is assuming that AppGameKit doesn't already do some pooling (which it may), I'm not that familiar with the engine under the hood!
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 12th Jan 2015 16:37 Edited at: 12th Jan 2015 16:41
With my experience, if you're going to use a sprite contentiously through the game, just hide it. For allot of my app games, I load and create everything, from the UI to obstacles, player, etc and either hide or move them off-screen until I need them.

From my own experience, when you set a sprite off-screen or it's hidden, AppGameKit won't render it. You can have hundreds of sprites created, but if they're hidden or off-screen there is no performance hit. This is from my own trial/error. I don't know the behind the scenes specifics.

Side Note: Stop with the bashing/attacks, keep your personal quips at the door.

<a href="http://www.slidedb.com/games/kayak-escape" title="View Kayak Escape! on Slide DB" target="_blank"><img src="http://button.slidedb.com/popularity/medium/games/34310.png" alt="Kayak Escape!" /></a>

Login to post a reply

Server time is: 2024-11-25 15:20:40
Your offset time is: 2024-11-25 15:20:40