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.

Newcomers AppGameKit Corner / help with sprite depth problems

Author
Message
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 23rd Jul 2020 18:20
i have a two road tiles, two cars, two background tiles and a text. these are all set to different depth in this order... text, car, road, and background. before i added the text everything was good but after, the background overlaps the car image even if i set the car to depth 0 and the background to 999. then when i remove the createtext for lootone it goes back to normal.

ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 25th Jul 2020 01:12
Have you tried creating the items in the order you want them displayed ?

For example, background, tracks, cars and then text.
If that works then you should not need to use any depth commands.
Never play leap frog with a unicorn.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 25th Jul 2020 05:10 Edited at: 25th Jul 2020 05:19
Quote: "Have you tried creating the items in the order you want them displayed ?"
that shouldn't matter since sprite depth is handled automatically unless SetSortCreated() is turned on:
Quote: "If two sprites occupy the same depth then the order they are drawn is undefined unless this function is set to 1"


otherwise, beyond a couple oddities in the code offered*, i don't see anything that should cause what you describe. try this simple code:

swapping the text creation order (or the order for any of it) provides the following consistently:

(and i have other more-complex code that produces what i'd expect depth-wise in other projects)

meanwhile, there's got to be more that you're doing beyond the code you've offered (which shows some set-up but nothing else) ?

for example, when i see all sprites set to 0 visibility in your code while you state "the background overlaps the car image", i wonder if you've set the car to visible, etc. (ie, there may be a mistake somewhere else that we can't see).

and, you're not using SetSortDepth() or SetSortTransparentDepth() anywhere, right? (where both are deprecated)

so, all i can suggest is to review your code :/

*then, said "oddities":

it's not good practice to load/store the same image multiple times where both sprites could be sharing the same image.
and:

= redundant

i mention them as a distraction and a friendly reminder to sweep/keep your code clean (which i tend to forget myself).

finally, if you can provide some (simplified but) inclusive code that demonstrates your issue, we'll do what we can to resolve
[My Itch.io Home]
[CODE lang=AGK] Your Code Here [/CODE]
[VIDEO=youtube] VideoID [/VIDEO]

Attachments

Login to view attachments
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 25th Jul 2020 07:18
I'm only using AGKS and text creation order will only matter regarding other text. (I think)

And with sprites, the creation order does matter regarding other sprites. So if you create your background sprites first and foreground sprites last then the Z order should be ok.
The Studio version seems to work that way without using any depth commands. I don't know how the older AppGameKit versions work.
Never play leap frog with a unicorn.
Virtual Nomad
Moderator
18
Years of Service
User Offline
Joined: 14th Dec 2005
Location: SF Bay Area, USA
Posted: 25th Jul 2020 07:40
i see. i don't use Studio (i just removed the Studio badge that somehow was applied); what does my code do under AGKS?
[My Itch.io Home]
[CODE lang=AGK] Your Code Here [/CODE]
[VIDEO=youtube] VideoID [/VIDEO]
ando
4
Years of Service
User Offline
Joined: 21st Feb 2020
Location: Australia
Posted: 25th Jul 2020 08:19
Your code still works fine in AGKS Virtual Nomad.

SetSortCreated() is deprecated in the Studio.

So your depth commands seem to be working fine.
I have not used depth commands so text is always in the foreground by default.
And I think sprite depth order is done automatically based on the creation order, unless I use the depth commands to override the creation order.

Never play leap frog with a unicorn.
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 25th Jul 2020 17:05
SetSortCreated() is also deprecated in Classic AFAIK

Virtual Nomad's code is working fine in both Studio and Classic, as expected...


PSY LABS Games
Coders don't die, they just gosub without return
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 25th Jul 2020 17:23
Thank you all and sorry for the late reply I'm on a mini vaca with the fam but I will definitely review all these suggestions
PSY
Developer
8
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 25th Jul 2020 19:45
I used your code with own images, and it works as it should, with and without the font ( AKGC and AGKS ).

I don't know the font you are using, so I used the standard font.
Also, car 2 uses some type for y positioning (panel.id), which I don't know the structure of, so I positioned the car with hard x and y values.
I also set all sprites to visible.

If the issue is neither caused by the font you are using, nor the panel type, it could be a rare bug.
Personally, I think that there's some error in other parts of your code, resulting in this strange behaviour.
It's extremely unlikely that there's a bug in the sprite depth routine of AGK.

Hard to tell without more code.


PSY


PSY LABS Games
Coders don't die, they just gosub without return
Qugurun
Valued Member
9
Years of Service
User Offline
Joined: 8th Dec 2014
Playing: AppGameKit
Posted: 26th Jul 2020 23:22
I think that the point was that the AppGameKit by default sets the depth of 9 for the text, which forces it to be on top of everything.



SetTextDepth and SetSpriteDepth help you set up the desired sequence.
Loktofeit
AGK Developer
15
Years of Service
User Offline
Joined: 21st Jan 2009
Location: Sarasota, FL
Posted: 27th Jul 2020 03:33

I don't know if this helps, but maybe the sort order is because it isn't storing the depth in your .id fields.

I've had problems with declaring UDT in this format:
global road as road_class[arraylength]

instead of in this format:
global dim road[arraylength] as road_class


Also, if you are using a single variable, you don't need to create a user type.
Instead of:
type city_class
id as integer
endtype
global city as city_class[1]


You can do:
gobal dim cityid[arraylength]

Was trying to make something of your code, but there's not enough there to get a solid idea of what you are doing.

I really do think you should check to see what your variables are storing. It's possible the order issue is because they're all at the same depth.
dandrews
4
Years of Service
User Offline
Joined: 26th Jun 2020
Location:
Posted: 29th Jul 2020 18:40 Edited at: 29th Jul 2020 18:44
Thank you all for the help I've certainly learned some new techniques from this. I had some "setspritedepth" within my main loop that didn't need to be there even though it was exactly what was in my setup as far as I could see when I removed it the issue solved itself. So it's possible the sprite were the same depth but maybe set in a different order in my loop then in my setup.
I know it's hard to help with limited code provided but I have a lot of graphics that I'd rather not have distributed and about 3000 lines so I'm trying to simplify it.

Login to post a reply

Server time is: 2024-11-21 12:43:53
Your offset time is: 2024-11-21 12:43:53