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 / SpriteScissor and offscreen sprites

Author
Message
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 22nd Mar 2013 21:22
I have potentially several thousand sprites in my game, spread over 8 screens.

I was wondering if it is beneficial to setSpriteScissor() to the screen, or is there no point - i.e. the renderer won't waste any time with offscreen sprites.

Similarly, I guess the visibility flag doesn't mean anything for these offscreen sprites either.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 22nd Mar 2013 21:41
Offscreen sprites do not render, but enough of them will slow you down anyway. I don't think visibility affects offscreen sprites, but I can't say for sure. If you have speed problems you probably need to lower the amount of sprites and reuse them. Basically you don't need sprites that are off screen, you only need enough to draw what's visible.


Demo 3 is out now!
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 22nd Mar 2013 22:04
I pre-set up a lot of sprites ready for using on a reusable cycle (e.g. my own particle stuff)
I already only initiate the particle system in the event that it is likely to be seen (within 0.5 screens of the current world offset), depending on scrollspeed, but the particle system could be partially visible / onscreen at any time thereafter, so my concern was to put a load of checks in to see if an individual element was onscreen/offscreen - lots of extra checks which may be worse than letting them be, versus just letting AppGameKit draw/not draw them.

If you remember, I dropped the setviewoffset() method for world management for a bunch of other reasons, but it would have been useless with the in-built particle system, which doesn't allow you to move (or offset) particles once they have left the emitter.

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 22nd Mar 2013 23:48
AGK will not send a sprite to the GPU if it is off screen, but it must still loop through all sprites to find the ones that are off screen.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 23rd Mar 2013 00:20
Will it skip processing the sprite if it is either set to invisible or deactivated?

I would rather perform the least number of checks if AppGameKit is already checking some..

ta

Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 23rd Mar 2013 00:27
If it is invisible then it will also be skipped, but it must still be checked every frame in case it becomes visible.
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 23rd Mar 2013 01:04
even if active is set false?

swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 23rd Mar 2013 01:08
Paul - instead of one large pile of assorted sprites, would it be possible to move hidden or deactivated sprites to a different storage pile so they would need not be looped over?

swis
Joined: Tue Dec 16th 2008
Interstellar
Paul Johnston
TGC Developer
21
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 23rd Mar 2013 01:10
Setting a sprite as inactive will just stop it from updating its animation, if it has one, but it must still be checked every frame. So if you have 2000 sprites AppGameKit will be doing a loop over all 2000 sprites checking if it should do anything with them.
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 23rd Mar 2013 02:02
Quote: "Setting a sprite as inactive will just stop it from updating its animation, if it has one, but it must still be checked every frame. So if you have 2000 sprites AppGameKit will be doing a loop over all 2000 sprites checking if it should do anything with them."

Well I'm asking if it's possible within AppGameKit to remove a sprite from the main pile so it doesn't slow down looping over it. Simply leave it in memory and not touch it until called back.

swis
Joined: Tue Dec 16th 2008
Interstellar
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 23rd Mar 2013 03:04
Yea, that would be good.
Save on the activate/deactivate, show/no show situation.

Sometimes it's hard to decide if you should clone sprites on the fly or premake them and use them off a stack.

Digital Awakening
AGK Developer
21
Years of Service
User Offline
Joined: 27th Aug 2002
Location: Sweden
Posted: 23rd Mar 2013 08:58
I like the idea of taking sprites off the loop. Not that I need this myself ATM but I know there are people who would want to use this.


Demo 3 is out now!
lilpissywilly
AGK Developer
13
Years of Service
User Offline
Joined: 10th Sep 2010
Location: Office Chair
Posted: 23rd Mar 2013 12:40
You could keep an array of UDT's with all the information needed to create a sprite such as x, y, image, size and so forth, and your "activate sprite" command would simply be a function to create a sprite from the array when needed?

My hovercraft is full of eels
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 23rd Mar 2013 14:11
You could just delete the sprie, but keep the image. It would be much quicker to create the sprite when it becomes 'active' than to reprogram the way AppGameKit works.

I live for video games! (And beers, and football, and cars!)
See what I live for here: [url]http:\\www.TeamDefiant.co.uk[/url]
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 23rd Mar 2013 16:56
Quote: "I like the idea of taking sprites off the loop. Not that I need this myself ATM but I know there are people who would want to use this."

I know Paul knows better than I do, but I'm glad to see I'm not nuts

There are certainly work arounds for the issue, but none of them could possibly be as efficient. Commands such as exists or whatnot could still treat these frozen sprites as if they didn't exist, in fact they practically would not, but a few commands to get or toggle the state could probably be quite beneficial.

swis
Joined: Tue Dec 16th 2008
Interstellar
nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 29th Mar 2013 23:38
I just removed 1.3Million multiplications from a loop called every frame by pre-calcing.

When I checked the before/after effect on CPU, it wasn't even noticable.

Guess I can survive the odd extra ifexists() call

Login to post a reply

Server time is: 2024-05-05 21:57:50
Your offset time is: 2024-05-05 21:57:50