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:
// Project: depth072420
// Created: 2020-07-24
// show all errors
SetErrorMode(2)
// set window properties
SetWindowTitle( "depth072420" )
SetWindowSize( 1080, 720, 0 )
SetWindowAllowResize( 1 ) // allow the user to resize the window
// set display properties
SetVirtualResolution( 1080, 720 ) // doesn't have to match the window
SetOrientationAllowed( 1, 1, 1, 1 ) // allow both portrait and landscape on mobile devices
SetSyncRate( 30, 0 ) // 30fps instead of 60 to save battery
SetScissor( 0,0,0,0 ) // use the maximum available screen space, no black borders
UseNewDefaultFonts( 1 ) // since version 2.0.22 we can use nicer default fonts
//depths:
back = 1000 : road = 900 : car = 800 : txt = 10
ThisText = CreateText("TEXT") : SetTextSize(ThisText,48) : SetTextDepth(ThisText,txt)
SetTextColor(ThisText,0,0,0,128) : SetTextAlignment(ThisText,1) : SetTextPosition(ThisText,128,108)
ThisCar = CreateSprite(0) : SetSpriteSize(ThisCar,32,64) : SetSpriteColor(ThisCar,128,0,0,255) : SetSpriteDepth(ThisCar,car)
SetSpritePositionByOffset(ThisCar,128,128)
ThisRoad = CreateSprite(0) : SetSpriteSize(ThisRoad,128,128) : SetSpriteColor(ThisRoad, 192,64,0,255) : SetSpriteDepth(ThisRoad,road)
ThisBack = CreateSprite(0) : SetSpriteSize(ThisBack,GetVirtualWidth(),GetVirtualHeight()) : SetSpriteDepth(ThisBack,back)
//ThisText = CreateText("TEXT") : SetTextSize(ThisText,48) : SetTextDepth(ThisText,txt)
//SetTextColor(ThisText,0,0,0,128) : SetTextAlignment(ThisText,1) : SetTextPosition(ThisText,128,108)
do
Sync()
loop
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":
car[4].img = loadimage("testcar5.png")
car[5].img = loadimage("testcar5.png")
it's not good practice to load/store the same image multiple times where both sprites could be sharing the same image.
and:
SetTextColorGreen(loottwo,255)
setTextColor(loottwo,0,255,0,255)
= 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]