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.

2D All the way! / Sprite Priority Dummy Spit

Author
Message
Ramsy
13
Years of Service
User Offline
Joined: 4th Jun 2009
Location: Melbourne
Posted: 9th Nov 2009 05:13
Someone please tell me there is an easy way to set sprite priority. I'm making a basic Mario style side scroller. But no matter whet I do the character stays behind background elements.

I'm going really really nuts over this.


I've tried set sprite priority. No Good.
I've tried paste sprite. No Good.
I've tried sprite priority based on sprite number. No Good.
I've tried simply drawing my animated sprite last. No Good.

For BASIC language I'm surprised this is isn't implemented.
Any help. Anything at all?
GIDustin
14
Years of Service
User Offline
Joined: 30th May 2008
Location:
Posted: 10th Nov 2009 03:36
set sprite priority

That is the command. If it isnt working, then you are probably using it wrong.

set sprite priority backgroundSprite, 1
set sprite priority marioSprite, 2

- GIDustin
Grog Grueslayer
Valued Member
17
Years of Service
User Offline
Joined: 30th May 2005
Playing: Green Hell
Posted: 10th Nov 2009 11:05
The easiest way is to not use SET SPRITE PRIORITY and let Darkbasic Pro do the priority the way does it naturally.

The old natural way was by the sprite number but with the newest update sprites are drawn by the image number used in the sprite.

Sprites that use image number 5 will always be drawn in front of sprite image numbers 1 to 5 and behind sprite image numbers 6 and up.

The following code snip creates 17 sprites with randomly created sprite numbers (shown at the top) and 1 to 17 image numbers (shown at the bottom) that are also randomly picked. It does it that way to show that it doesn't matter when the sprite or images are created... they will always be in the order of the image number used in the sprite.

One sprite will follow the mouse with an image number that can be changed by hitting the spacebar. Once the image is changed move the box (via the mouse) close to the other sprites on the screen and you'll notice (based on the image number) it'll go above any sprite at or lower than the image number and be under any image number above the current image number.



Login to post a reply

Server time is: 2023-01-29 06:17:22
Your offset time is: 2023-01-29 06:17:22