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 Studio Chat / [SOLVED] Is there a Commands/Functions to list all sprite ID's?

Author
Message
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 28th Feb 2021 09:18
Goodday Everyone

Few Quick Questions:
1. Is there a command/function that can tell me "ALL" sprite ID's... and "ALL" text ID's

in my APP.
I use "manual" assigned ID's. example
All Sprites for "Background" images is eg: 1000-2000
All Sprites for "Tiles" is from 3000 - 4000
All Sprites for "Collectables" is from 5000 - 6000
etc...
And there is also a few Sprites create by AGKS Editor with their own ID from AGS

this been said. Some Sprite create in CODE and some in the DESIGNER.
Let say for example I want to "BULK" update all sprites , SETSPRITEDEPTH(????, 1) or Make all sprites Visible/Hide

or

Will it be better to create an array for all ID's



Or any other idea?


The author of this post has marked a post as an answer.

Go to answer

Zaxxan
AGK Developer
3
Years of Service
User Offline
Joined: 17th Nov 2020
Location: England
Posted: 28th Feb 2021 09:42
I don't think there are any specific commands, I've certainly not come across any. I have followed the same approach as you where I group the sprites into different ranges. The only way I can think of determining which ones have been used is to create a for next loop and use the getspriteexist command etc and then add them to an array.

I'm fairly new to Appgamekit though so more experienced users may have a far better/easier way of doing this.
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 28th Feb 2021 11:40
This post has been marked by the post author as the answer.
There is no "Command" per se., but you can create a function like:



Now this will check all 4.2 Billion POSSIBLE IDs that you can use for something., and then it will store it in an Array you pass in.
So, for example you'd use it

SpriteTable As Integer[] : GetAllSpriteID( SpriteTable[] )

Now that Array will contain every Sprite ID when you called that Function., regardless of how they were created.
What's more is it will ONLY contain specifically the number of Elements that equals how many are used...

So say you've created 2000 Sprites between you and say the freely available Particle Plug-In; then it will have a SpriteTable.Length of 2000
And actually we can improve this by creating a Type to also store Flags for the Asset Types that share / use said ID.

In this respect we can essentially use the same loop to store ALL ID Instances.
But I'll let you figure that one out.
Another thing we can do is have an Automatic ID System.

e.g.


Now you can define the AssetType_<Type> with whatever number you want... I'd argue this is a good reason for AppGameKit to support "Enum" or "Enumeration" Types; which in C/C++ are just a handy way of having automatic numerical assignment.
But you can do this (with less performance overhead than using a variable) by defining these with #Constant
And as noted these can be ANYTHING you want, as long as they're unique and assigned to something memorable for you... I'm just using AssetType_<Type> as an example

In this way it will check all Available IDs from the Lowest Possible., until there is no longer an Asset (of that Type) with that Assigned ID; then you can use it as "Manual" Assignment.
It's actually a pretty clean way of handling ID Assignment, as generally speaking you'll find all the Assets are then numbered in Order (most of the time)... this is fine for "Small" or "Simple" Projects where you're going to be creating / deleting assets in order.

For more complex projects I actually use 2 Additional Functions along with a Global AssetTable (which uses a Type that has an Array for each Asset Type)
In essence these Functions are "NewAsset( )" and "ReleaseAsset( )"

The idea being that these essentially handle Creating a New Asset, Generating an ID (with the above Function) and then Adding them as Entries into said AssetTable...
Release does the same thing., but obviously Deletes the Asset, Removes it's Table Entry and then Sorts the Array ( to ensure IDs are ALWAYS in Ascending Order )



This might seem like a lot of extra work., but in essence at the end of the Program all I have to do is have a simple For...Next Loop for each Asset Array; which then Deletes everything that is "In-Flight" at the time.
As a note, this isn't strictly necessary with AppGameKit as it'll do this automatically anyway... still I'm more typically programming in C++., where this doesn't happen; and it's easy to accidentally leave things resident in memory; so it's more a habit at this point.
DannyD
6
Years of Service
User Offline
Joined: 29th Aug 2017
Location:
Posted: 28th Feb 2021 12:38
Thanks Raven.. this information is much appreciate and valuable.

Will defnitly solve my problem

Appreciate
Danie
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 28th Feb 2021 14:23
You can use GetManagedSpriteCount() to get how many sprites are currently being managed by AGK. That way you can set up your for/next loop without having to check for millions of sprites that don't exist.
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 28th Feb 2021 23:31
Quote: "You can use GetManagedSpriteCount() to get how many sprites are currently being managed by AGK. That way you can set up your for/next loop without having to check for millions of sprites that don't exist."


Yeah, that Command is a Performance Metric for the Sprite Manager... doesn't really have much to do with what the OP was asking.
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 28th Feb 2021 23:50 Edited at: 28th Feb 2021 23:53
*sigh*

It was meant to determine what's the current max number of sprites and then set up your for/next loop instead of needlessly counting to 0xFFFFFFFF for absolutely no reason. You know... as I quite obviously stated. For a guy who complains about people not reading what he writes....
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us
Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 1st Mar 2021 10:45
Quote: "It was meant to determine what's the current max number of sprites"


GetManagedSpriteCount( ) provides you with the number of Sprites that are (in that Frame) currently being Managed by the Sprite Manager.
As such., in order for a Sprite to be counted it must first be "Active" otherwise the Sprite Manager ignores it.
Then it has to actually have to be subscribed to one of the features that the Sprite Manager Handles ... such-as Animation, Tween / Interpolation Movement, Physics, Depth, Drawing, etc.

If you are Managing the Sprites (even some of them rather than all) yourself... then those Sprites aren't included in said Count.
In essence for a Sprite to be Counted it must be "Active" and "Visible" otherwise the Sprite Manager ignores it.

...

Yes, I understand that my "Catch All" approach is slow (about 2 Seconds) and might seem wasteful as you'll rarely, if ever have 4.2 Billion Sprites.
But the point is that it will give you a definitive "This is how many Sprites you have" and "These are their ID Numbers"
What's more useful here is., the Sprite Table Array; can easily be For..Next Looped., as it's values are ALWAYS going to be 1 to ArrayElementCount - 1
Regardless of what Sprite IDs (or other Asset Types; you can use this for anything... Images, Objects, Mesh, Shaders, Text, etc.) are.

Remember we can set Sprite IDs to WHATEVER we want.

So we can do something like:

CreateSprite( 0xA8, Image )
CreateSprite( 0xF3, Image )
MySprite = CreateSprite( Image )
CreateSprite( 0xFF4E, Image )

And well there you have 4 Sprites; but you can't For..Next those ID Values.
Not because I'm using Hexidecimal but because they literally not incremental values.
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 1st Mar 2021 11:33
Quote: "
GetManagedSpriteCount( ) provides you with the number of Sprites that are (in that Frame) currently being Managed by the Sprite Manager.
As such., in order for a Sprite to be counted it must first be "Active" otherwise the Sprite Manager ignores it.
Then it has to actually have to be subscribed to one of the features that the Sprite Manager Handles ... such-as Animation, Tween / Interpolation Movement, Physics, Depth, Drawing, etc.

If you are Managing the Sprites (even some of them rather than all) yourself... then those Sprites aren't included in said Count.
In essence for a Sprite to be Counted it must be "Active" and "Visible" otherwise the Sprite Manager ignores it.
"


Not here. All of my sprites are inactive, no physics, and the command still returns the correct number of sprites even if they are all set to invisible. Whether or not the command is working as intended is up to debate.. but the end result is that right now, that command returns the total number of sprites you have, period.
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us
ruckertheron
7
Years of Service
User Offline
Joined: 12th Nov 2016
Location:
Posted: 1st Mar 2021 13:43 Edited at: 1st Mar 2021 13:45
Quote: "Not here. All of my sprites are inactive, no physics, and the command still returns the correct number of sprites even if they are all set to invisible. Whether or not the command is working as intended is up to debate.. but the end result is that right now, that command returns the total number of sprites you have, period."


What I got from this and why I would agree with Raven is because of sprites mainly created by AppGameKit assign their ID numbers. If I create 8 sprites from 101 to 108, and then let AppGameKit assign numbers, your 9th sprite will have the ID 100001 which will be passed in a 1 to 9 for: next loop but Im not at as advanced as both of these gentlemen here and I could be missing something.
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 1st Mar 2021 21:58
Quote: "What I got from this and why I would agree with Raven is because of sprites mainly created by AppGameKit assign their ID numbers. If I create 8 sprites from 101 to 108, and then let AppGameKit assign numbers, your 9th sprite will have the ID 100001 which will be passed in a 1 to 9 for: next loop but Im not at as advanced as both of these gentlemen here and I could be missing something."


Ah yeah... from that point of view then, that would indeed be correct.
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us
PartTimeCoder
AGK Tool Maker
9
Years of Service
User Offline
Joined: 9th Mar 2015
Location: London UK
Posted: 1st Mar 2021 22:19
This actually highlights the lack of foresight from TGC when adding the core functions, GetManagedSpriteCount( ) is for what exactly, what can I do with it, OH, get the number of sprites created, ok then what, how will this help me..... it wont, without GetManagedSpriteID( index )

Anyhow, you really should be thinking about resource management the moment you create a project, load everything into a type/array so you have instant access from the get-go.
n00bstar
20
Years of Service
User Offline
Joined: 9th Feb 2004
Location: Montreal, Canada.
Posted: 1st Mar 2021 22:39
Quote: "This actually highlights the lack of foresight from TGC when adding the core functions, GetManagedSpriteCount( ) is for what exactly, what can I do with it, OH, get the number of sprites created, ok then what, how will this help me..... it wont, without GetManagedSpriteID( index ) "


Well... it's a benchmarking tool really. It could be used to isolate a weird crash cause by some rogue function that creates a few dozen sprites every 10 minutes or something weird like that. Seeing the number of sprites go up when it shouldn't would help you isolate what's going on.

Quote: "Anyhow, you really should be thinking about resource management the moment you create a project, load everything into a type/array so you have instant access from the get-go."
Oh yeah! I don't think I ever created any sprite that is not safely tucked away in a type.
-----------------------------------------------------------------------------
We all got a chicken duck woman thing waiting for us

Login to post a reply

Server time is: 2024-04-23 23:53:40
Your offset time is: 2024-04-23 23:53:40