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.

Author
Message
rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 29th Nov 2010 08:32
Is there any way I can reneame my Sprites once they are on my screen?
=PRoF=
23
Years of Service
User Offline
Joined: 17th Mar 2003
Location: Milton Keynes, UK
Posted: 29th Nov 2010 10:44
Erm, I'm not sure I understand the question?

In what way do you want to "rename" the sprite?

baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Nov 2010 10:47
What do you mean by "re-name"?

You assign an integer to a sprite on creation and can assign the value of that integer to a variable to make it easier to refer to (and edit) in-game.

If you want you can assign that value to multiple variables for different uses.

Can you provide some code that I can explain this better with? Or am I misunderstanding the question?

rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 29th Nov 2010 13:38
What I would like to do is take a sprite named 5, and rename it to be sprite 4. I like my sprite names to match up with my array count.

sprite 1, Xpos, Ypos, imageNumber
Sprite 2, Xpos, Ypos, ImageNumber
Sprite 3, Xpos, Ypos, ImageNumber

I have 3 sprites
now I make an array

dim SpriteAmount(3)

For a = 1 to array count(SpriteAmount())
sprite a, Xpos, Ypos, ImageNumber
next a

What I just did was use my array count to put my sprites on the screen.

Now say I need to delete array element #2
I would also delete Sprite 2

Now I have a 2 element array count but if I try to use array count
for the sprite numbers I only go up to 2 on array count and
my remaining sprites are named 1 and 3.

If I could reneame sprite 3 to sprite 2 it would help in my caculations for my game and keep my number counts down and eisier to keep track of. It is not a big deal as I can just keep track of all my variables, I was just wondering if there was a way to rename a sprite. I hope i did not confuse anyone, I am kinda new to this programming. Thanks for any replies. I appreciate them.
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Nov 2010 13:50
One way to deal with this kind of thing would be to use "User Defined Type" (UDT) arrays. That way you can have a flag in the array for whether the sprite needs to be used.

Example:


Then when you come to display the sprites:


IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Nov 2010 14:53
Quote: "What I would like to do is take a sprite named 5, and rename it to be sprite 4"

Clone sprite 5 to 4, then delete sprite 5.

... but the best way is what baxslash has posted, although I would advise against pasting sprites (that way is slower than simply allowing the sprites to draw themselves ... that's due to recent changes to code).

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
baxslash
Valued Member
Bronze Codemaster
19
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 29th Nov 2010 14:59
Quote: "I would advise against pasting sprites (that way is slower than simply allowing the sprites to draw themselves ... that's due to recent changes to code)."

I didn't know that, thanks IanM! I guess I'd better start using sprites properly then...

Why was it changed (If you don't mind me asking)?

IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 29th Nov 2010 20:24
Pasting sprites hasn't changed at all - drawing sprites normally changed. I pretty much re-wrote the rendering loop to make them faster for 7.5.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 30th Nov 2010 20:25
Quote: "I pretty much re-wrote the rendering loop to make them faster for 7.5."


When are you going to re-write the rest of it?
rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 1st Dec 2010 03:32
Is there a way you could design a rename sprite command Ian, also, i tried using the paste sprite command and it did not work to well for me, I ended up having to use the sprite command to get my sprites moving.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 1st Dec 2010 10:19
Did you see where I wrote:
Quote: "Clone sprite 5 to 4, then delete sprite 5."

That's how to 'rename' a sprite. CLONE SPRITE and DELETE SPRITE are the commands you should use.

@Green Gandalf,
I can see that you're not really paying attention: http://code.google.com/p/darkbasicpro/source/list :p

3D Maths was pretty much a complete rewrite, and the Music plug-in was reorganised around classes.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd Dec 2010 02:07 Edited at: 2nd Dec 2010 02:51
There, a "rename" function. Assuming the new sprite id doesn't exist, but I think DB overwrites that silently if I remember.




Ian, I didn't know DB development was being tracked on Google.

"Only the educated are free" ~Epictetus
"Imagination is more important than knowledge..." ~Einstein
rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 2nd Dec 2010 02:50
I was paying attention, I was hoping there was a way to rename without cloning. Here is why I was trying to avoid cloning. I have 100 sprites, labled 1 to 100, I like to match my array count with the sprite name if possable. In the future I might have 1000 sprites. if i delete array element 50, i want to delete sprite 50.
so far no problem. now the array automatically adjusts all records 1, so array 51 is now array 50. if i have to go in and clone 50 sprites, i figure that is alot of processing power. This is just something I was wondering, I have paid attention and understand what you have taught me. I figured if there was just a way to rename the integer name of the sprite, it would take alot of processor time off of the function. If I have 1000 sprites I have a feeling that will required some real doing for the processor. The way I am doing it now, i am using 2 arrays, the first array is the master and i don't delete any records, i use a flag technique that baxslash taught me. then i use a second array to fill up all the sprites that i am processing at that time. I am sorry if I came off wrong, I am pretty new at programing and can only see in tunnel vision. Thank you for your help. I really do apreciate you getting back to me.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 2nd Dec 2010 13:23
OK, I kinda understand why you want to do it this way - if you asked before you started coding, then I'd have suggested a array of UDT's containing the sprite id, removing this as a problem completely.

However, here's how I'd fix your existing code:

When you want to 'kill' an existing sprite, you currently delete its array element (shifting all further elements down 1 automatically), then you 'rename' the sprites above to close the gap (51 becomes 50, 52 becomes 51 etc).

Instead of deleting the array element, copy the data from the last element into it, then delete the last element in the array. Then you can do the same with the sprite - clone the last sprite over your 'killed' sprite, then delete the last sprite.

Now that may not work depending on what else you are doing in the code, and whether a sprite id has any relevance beyond being just an id. Only you can know that.

Utility plug-ins (26-JUL-2010)
I'm applying terms of use that require you to wear a red nose and honk a horn whenever you use the Internet
rolo9
16
Years of Service
User Offline
Joined: 1st Jan 2010
Location:
Posted: 2nd Dec 2010 20:57
That is brilliant, Thank You. That will save a bunch of processing. Thank you Thank You Thank You

Login to post a reply

Server time is: 2026-07-21 13:38:34
Your offset time is: 2026-07-21 13:38:34