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.

DarkBASIC Discussion / Would anyone use a sprite priority function set

Author
Message
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Mar 2009 07:45
because db doesn't have a set sprite priority command i was thinking of doing this but i was wondering if anyone would use it? its quite simple(the idea anyway) you would setup your sprites with the functions and (in my FIRST idea) you would just call a function like refresh sprites and it would put them in the order you had them set as what do you all think?


a couple of arrays and a splotch of x and y coordanets.... maybe a dash of salt er um sorry.... lol but anyone interested?
Quirkyjim
16
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 8th Mar 2009 17:17
Well, I guess you would just be making separate bitmaps, then pasting the images to them, then making sprites in the order of priority that you want. That's what you want?

~QJ
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 8th Mar 2009 20:11
Actually I was saying would anyone use it if I made one. And why the complexity? Why not just use arrays and store the sprite info then when you update them, call the sprite command in the order that the user sets the priority? Sounds like it would work in my mind and then the user would be able to use the internal sprite commands still.


For your idea do you mean pasting the images on a offscreen bitmap and copying the bitmap the bitmap 0? That wouldn't be sprite at all would it?
Libervurto
18
Years of Service
User Offline
Joined: 30th Jun 2006
Location: On Toast
Posted: 8th Mar 2009 20:38
PASTE SPRITE
This was one of my first questions on the forums, the paste sprite command will draw its sprite over everything else.
I don't think this command cleans up after itself though so you might need a backdrop to wipe the screen or something, try it first though cos im not sure of that.

The Universe has been erased by a mod because it was larger
than 240x80 pixels.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Mar 2009 02:22
yes that does paste the sprite on top BUT you cannot test for collision with it as it is not the actual sprite more like the image that made the sprite lol

paste sprite is pretty much just paste image just it goes ontop of everything.


the actual sprites them selves have priority built in its just the priority is the order they are called. so if you (in this case) called a function lets say for example the function makesprite(sprite,x,y,image,Priority) then in that function you stored all this information in some arrays then in your loop called another function named refreshsprites() it would use a for next loop and paste the sprites in priority order. see what i'm thinking? not sure if it would work still trying to squeeze out the kinks in my planning as up to now this has all been in my head :/ lol
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 02:43
You can use paste sprite if you use hidden sprites you'll still be able to check for collision. Plus with hidden sprites, you can turn off the auto refresh and the fact that they are hidden you'll more than double performance.

But for the sake of priority, it all comes down to what happens first and last so an ordered array would do the trick. You're definately on the right track!

Ashingda posted an example of using the quick sort algorithm to prioritize an entire screen filled with circles. You might want to hunt that down to give you some ideas and also note the fast implementation of sorting for priority.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Mar 2009 02:55
thanks latch.


that post probebly would be veryvery helpful thanks


the only problem i'm running into is you have to update them at the same time. i know that is the only way to do it(in my mind) but that cud cause problems hmmmm
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 03:27
Well, let's say you store all of the references to sprites in an array. You also keep track of the position, the priority and the the image number. The priority can be handled in 2 ways. With a min to max or with a True or False. The true or false would be the easiest and maybe the quickest because you only care about 1 sprite having the highest priority. The others don't matter their priority would be 0. With the min to max, the priority ranges from 1 to the total number of sprites used. Then the sprites are displayed according to that range.

So after you decide on the priority method, you decide on a selection method. Does the user click on the sprite, type a number, whatever. Once the selection process begins, you have to set the priority. One method of setting the priority is to first get the current priority of the object cliked on. Then search through the array until you find the object with the highest priority, then swap those two priorities and you are done. Have a display algorithm that displays the sprites according to their priority. In the true false method, the display may look like:



In the min max priority the display may look like:



In each scenario, you may have the actual sprite number stored in the array. You'd use that in place of s in actually rendering the sprite. But your array's first index will always range from 1 to maxsprites.

Instead of just swapping the two prorities (which is fast performance wise because once the highest priority is achieved you don't have to go any further through the loop to find the next priority). But sometimes you will want to shift all of the rest of the priorities up or down. So if there were 10 sprites, and number 5 became top priority, former 10 becomes 9, 9 becomes 8, 8 becomes 7, 7 becomes 6, 6 becomes 5, and 5 becomes 10. For a windows type app, this isn't necessary. But for a game where you want items to stay behind or in front of other items, it can be important.

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Mar 2009 03:42
hmmm alot of very very good info lol

i don't quite know what you mean about clicking. i was going to leave setting the sprite priority up to the user sorta like dbp using a set sprite priority type function so esenchaly(that is so the wrong spelling ) i would be duoplicating the dbc sprite commands just adding a priority. good point with the true false thing i might try that as a start off and then maybe use the other method. yes i will do that i will start work write now this is the one good part of having no life... lots of coding time
Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 9th Mar 2009 03:56
Never mind the clicking. That was just filler for the user deciding when they wanted to use prioritization. The implemenation would be in the form of functions or subroutines. Have Fun !

Enjoy your day.
Caleb1994
16
Years of Service
User Offline
Joined: 10th Oct 2008
Location: The Internet you idiot!
Posted: 9th Mar 2009 04:11 Edited at: 9th Mar 2009 04:47
lol oh ok i see yes form functions were my insperation for this but i'm having a problem i just wrote this up and it's pasting the sprite but the x position of sprite one every time is off by some actually the higher the initial x position the bigger difference between where it should be and where it is. heres the code.



Edit:

wait no it does the offset by witch Makesprite function is called first. when sprite 2 is called first that one is offset if sprite 1 is called first then it is offset hmmmm i don't get it lol


Edit2:

Never mind i put the part where it sets SpriteX(Sprite)=X and spriteY(Sprite)=Y at the beginning of the function and it works i also added a Spritetofront function heres the new code

Login to post a reply

Server time is: 2025-05-16 08:57:55
Your offset time is: 2025-05-16 08:57:55