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 Professional Discussion / Converting Integers to Sprites

Author
Message
Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 16th Nov 2003 04:22 Edited at: 16th Nov 2003 04:23
My question is, what is a good method of converting a variable that consist of a number into a sprite/s? Below, I have a not-quite-finished function that would (Hopefully) place a sprite on screen based on what number it was.



I've already tested a smaller, more complete version (on a different PC), but in the process, I found two problems/questions. 1: I'm hoping to make numbers up in their 1000's, so what would I do if the number consisted of several of the smae digit, such as 1552?

2: I doubt my method is the best way of going about what I want to acheive, or the easiest. Does someone know of a better method?

All suggestions/corrections appreciated!

Usermlsra - Causing Havoc with a Smile
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 16th Nov 2003 04:52
heres mine
I always load in my number pictures 1000-1009 and set my sprites 1000-1010 for 11 digits make more if needed.
Mine is set to use 24 pixel wide number pictures
and I send a number not a string to my function, but you can change that real easy.
anyway now that you know how it works here it is.

Rwilson
23
Years of Service
User Offline
Joined: 19th May 2003
Location: United States
Posted: 16th Nov 2003 09:04 Edited at: 16th Nov 2003 09:06
! Why didn't I think of that! Darn you brain, the problems you cause by not working right!

That little funtion will work very well indeed! However, one little thing. Each time you run it, it will replace the previous number printed on screen, thus limiting it to one task. However, this could be resolved by being able to enter the sprite starter number, like so:



On a final note, you should put this in the code base, I'd been looking through there for something like this and saw nothing. And I doubt I'm the only one whose looking for something like this.

Usermlsra - Causing Havoc with a Smile
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 16th Nov 2003 16:33
Ok, I put it in the code base. I didn't have anything in there anyway. I did modify it so it won't matter what size your numbers images are.

heres the up date and a example file.


CTP

Lifes short, try to enjoy it and not take it to seriously!
Rob K
Retired Moderator
23
Years of Service
User Offline
Joined: 10th Sep 2002
Location: Surrey, United Kingdom
Posted: 16th Nov 2003 17:24
I strongly suggest that you don't worry about assigning ranges of image no.s just write a function to return an available (unused) image id and assign it to a variable.




BLUE GUI Plugin: http://blue.robert-knight.net / BLUE IDE [href]http://blueide.sf.net/ - Replacement editor for DBPro[/href]
CloseToPerfect
23
Years of Service
User Offline
Joined: 20th Dec 2002
Location: United States
Posted: 16th Nov 2003 20:18
in Blitz thats how I would do it, just load the image into the array but I way trying to keey it simple in Dark Basic for him.

you could do it like rob suggests the sprite line would be

sprite SpriteNumber+i,x+(i*sprite width(SpriteNumber+i)),y,num(val(mid$(number$,i)))

Just remember if you load some of your images this way you must load all of them this way or you could overwrite a image slot.

personnally with a range of 65000 images slots in DB I just plan out my image usage first 0-100 background image 100-200 objects 200-300 foreground ect. I find it fairly simple to manage them all this way, even when there are several hundred.

On another note Robs method makes deleting the image after the program a little faster as with mine I check the whole range of images where Robs once you found the last image to delete your done.


"everything in its place and a place for everything"

CTP

Lifes short, try to enjoy it and not take it to seriously!

Login to post a reply

Server time is: 2026-07-26 20:14:43
Your offset time is: 2026-07-26 20:14:43