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 / Setting Sprite to invisible VS positioning Sprite off-screen

Author
Message
Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 12th Nov 2018 02:16 Edited at: 12th Nov 2018 13:40
Hi,
It happens very often that you have a (NON-PHYSICS) sprite that you will be using again (and hence don't want to delete it), but that you want to get rid off for the time being.
I've seen people say or do one of these two options; that is, some people will put sprites at, say, (-10000,-10000), while other may use setVisible(false).
I couldn't find anything about it on the forum.
Are both of these options equivalent?
AppGameKit 2018.10.10

iMac Book Pro, MacOS 10.14, Xcode 9.4.1;
iPhone 6, iOS 12; iPad (3rd gen), iOS 9.35; iPad Pro 12'9 (2nd gen), iOS 12.

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2017;
smallg
Valued Member
18
Years of Service
User Offline
Joined: 8th Dec 2005
Location: steam
Posted: 12th Nov 2018 10:06
Personally I think off screen is better as it ensures things like collision also stop being a potential problem without needing to do extra code to switch it all on/off each time.
Also I'm pretty sure performance hit is higher for sprites on screen but invisible Vs sprites visible but off screen (off screen and invisible is likely the best).
life's one big game
spec= i5 4ghz, 16gb ram, Nvidia 1070ti gpu
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Nov 2018 11:13
From my tests (using 10,000 little solid-colour sprites) I get the following results over 30 seconds:

on-screen, but active and Invisible: 17598 frames served
on-screen, but inactive and invisible: 20337 frames served
off-screen, but active and visible: 12097 frames served
off-screen, but inactive and invisible: 20215 frames served
Having them all on-screen, active AND visible gives me just 284 frames in 30 seconds... however, if you delete all the sprites you don't need (in this case, all of them), I get: 63584 frames served over 30 seconds.

So, making a sprite inactive also makes a big difference to framerate, but deleting sprites that aren't required, and re-building them when needed is probably going to make the most difference (as long as it isn't every frame of course). I guess it depends how often the sprite needs to be hidden.

Jerry McGuire
7
Years of Service
User Offline
Joined: 25th Mar 2017
Location:
Posted: 12th Nov 2018 13:47
@smallg: Thank you, though I meant for non-physics sprites.

@CJB: Those are very useful numbers. Since my question was meant for non-physics sprites, I can simply compare the numbers you got for inactive sprites. That would mean invisible and off-screen are practically equivalent. Thanks a lot!!

AppGameKit 2018.10.10

iMac Book Pro, MacOS 10.14, Xcode 9.4.1;
iPhone 6, iOS 12; iPad (3rd gen), iOS 9.35; iPad Pro 12'9 (2nd gen), iOS 12.

Dell Precision T7400, Windows 7 Professional 64bit, Visual Studio Community 2017;
CJB
Valued Member
20
Years of Service
User Offline
Joined: 10th Feb 2004
Location: Essex, UK
Posted: 12th Nov 2018 15:05
No problem. I used SetSpriteActive(Sprite ID, 0), and SetSpriteVisible(Sprite ID,0).

Login to post a reply

Server time is: 2024-04-19 21:29:35
Your offset time is: 2024-04-19 21:29:35