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.

Dark GDK / trying to get 16 sprites from 1 bitmap image seem to have problems ....

Author
Message
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 05:12
Hello folks.

I have an image that consists of 16 images all 96 x 96 pixels
arranged in a 4 x4 format. Need get these images into 16 individual sprites. I made this code but cannot seem to get the sprites to display on the screen. I am assuming that i have got something wrong here. Please has anyone got any ideas on this.

Thanks for any possible help :- Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA

Attachments

Login to view attachments
Gatorules
15
Years of Service
User Offline
Joined: 17th Dec 2008
Location:
Posted: 17th Feb 2009 05:17
as far as i know you have to create sprites seperately and cant divide a picture into different sprites. do you mean animation frames possibly?
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 05:24
I do not want 1 sprite with 16 individual frames. I need 16 individual sprites using the 16 different images from the one image. I can get 16 images into one sprite but thats not what i need. I need to display the 16 images individually without creating 16 sprites each with 16 images in them. hope that makes sense...

Regards :- Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 06:29
Looking at the function dbCopyBitmap it does seem possible to take an image and split it up into separate images then make those into sprites. Or am i wrong here it seems logical but ...

Regards Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 17th Feb 2009 07:20 Edited at: 17th Feb 2009 07:23
What I would do is load the file using the dbLoadBitmap() function. That will not only load it but also set it as the default surface for drawing (back to that in a sec). Then, cycle through your bitmap grabbing images with dbGetImage(). Once you're done, call dbSetCurrentBitmap(0) to reset the screen as the default drawing surface (remember what I said about dbLoadBitmap()?).

Now all you need is to make your sprites using the 16 images you acquired. Here's a little code snippet:



Then you can just set your sprites using those 16 images.

Hope this helps,

-Frank

[edit]

I almost forgot, once you've gotten your images you can probably delete the bitmap if you don't need it anymore. Just call dbDeleteBitmap(whatever number you used) on it.
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 07:52
Thank you frank for that code i shall try that.

Trying to create a do it all function that uses dbCopyBitmap
and a few other functions to try and make it simpler to get a tiled image into sprites. Your idea looks sound to me.

Regards :- Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
Pharoseer
17
Years of Service
User Offline
Joined: 21st Feb 2007
Location: Right behind you
Posted: 17th Feb 2009 09:11
Glad I could help, Steve. I use that method often and it works well for me. With bitmaps you'll have to be careful as I believe you're only allowed 32 of them at a time. That's why I tend not to use dbCopyBitmap() and instead use the image functions whenever possible. Of course, the 32 bitmap limitation might not exist anymore. I guess it's time for me to learn something new.

-Frank
Diggsey
18
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 17th Feb 2009 13:17
Why not just use:
dbGetImage(imgnum,tilex,tiley,tilex+tilewidth,tiley+tileheight,1);

dbSprite(spritenum,x,y,imgnum);

[b]Yuor signutare was aresed by a deslyxic mud...
BOX2D V2 HAS HELP FILES! AND A WIKI!
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 22:07
Thank you Diggsey that seems a nice way to it also.
I wonder if other readers of this post have a different
way to do this also ?. There does to be a couple of commands that could be used to produce the same effect. My thinking was that using the dbCopyBitmap actually saves some time as it does 2 tasks in one ... Copying from and to an image in the same function.
I assume that you do not have to setcurrentbitmap if using that function ? So much to understand about darkGDK...

I have not been using darkGDK for too long so as far as that goes i am somewhat a newbie.

Perhaps we could have a sort of contest here ??????
The neatest smallest way of getting a tiled 4x4 image into
16 different sprites.

Thanks guy for your responses to this post
Regards teve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 22:18
I love the dbCreateAnimatedSprite function. Because that does all the work for you. BUT how could you then take those sprites and put them into individual sprites. ??? I guess using pointers may be an answer to that but how ????

Regards Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Feb 2009 23:31
I've said it before and I'll say it again, "have a look at dbSpriteTextureCoords(). Each of the sprites references the same image but the function allows you to tell which decimal fraction of an image any given sprite will use.

I've used this method to create an odometer with five digits using the same image but picking out the individual numbers from the strip.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 17th Feb 2009 23:39
Thank you Lilith any chance of an example of its use please ?
Regards : - Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 17th Feb 2009 23:47 Edited at: 17th Feb 2009 23:57
Opps! Got the name of the function wrong. It's dbSetSpriteTextureCoord().

The following is a function to set the corner coordinates of an image that's applied to the sprite. It assumes that the image has already been assigned to the sprite.



So, to tell sprite number 1 to use the upper left 1/16th section you call

spriteSection (1, 0.0f, 0.0f, 0.25f, 0.025f);

For sprite number 2 to use the same size section to the immediate right

spriteSection (2, 0.25f, 0.0f, 0.50f, 0.25f);

If sprite 5 was to use the section just below the first

spriteSection (5, 0.0f, 0.25f, 0.25, 0.50f);

This may also require you to resize your sprite to get the needed results.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 18th Feb 2009 00:26
Thank you for that example. I shall be using that as a basis for a new function here. It is a shame there there is not a function that works like dbCreateAnimatedSprite but also has the ability to take the tiles and directly put them into a range of sprites.

Something like this

dbCreateAnimatedSprite ( int iSprite, char* szFilename, 4 ,
4 , int iImage, intosprite1 , intosprite16 );

Maybe this could be an addition to any further darkGDK releases?. I feel sure that it would be of use to many folks out there and would make life a whole lot easier.

Thank you.

Regards :- Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
stevebrit
15
Years of Service
User Offline
Joined: 6th Jan 2009
Location: Florida USA
Posted: 20th Feb 2009 07:38
Hello i still cannot solve my problem with getting an image that has tiles on it, into separate sprites. If someone could spell it out for me perhaps i can see what i am doing wrong.
They are being created or at least empty bitmaps are.
If i check to see if they exist the relevant image numbers do exist.

I have an image that has 16 tiles on it the size of the image is 384 x 384 so of course thats 4 x4 images @ 96 x96 pixels each tile.

I need to get these images into separate sprites :-(

If someone could show me the code i would need to get these displayed on the screen in a working form i would be so pleased having tried so many different things to get it to work.
I know i am doing something wrong but cannot see what it is.

Regards Steve

AMD Athlon64x2 3.1Ghz - Ram 4Gb DDR2 800Mhz - 500Gb HD
Ndivia 9600GT SLI - 24in LCD - WIN 7 - 64 bit BETA
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Feb 2009 17:13
When you load your image, what texture flag are you using?

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Lilith
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location: Dallas, TX
Posted: 23rd Feb 2009 23:52
Have a look at the source code for the Dark Invaders demo that comes with Dark GDK. It has an explanation of how to use a subdivided bitmap to make sprites to represent text on the screen.

Lilith, Night Butterfly
I'm not a programmer but I play one in the office
Scottie Dog
16
Years of Service
User Offline
Joined: 12th Feb 2008
Location:
Posted: 2nd Mar 2009 09:31
The code posted by Pharoseer is about right.
The only thing to add is that you need to create the bitmap before loading it...
dbCreateBitmap ( someNumber, 96*4, 96*4);


and change the *24 used in dbGetImage into the size of your required sprites, in this case *96. (I've also added a 1 to the end)
dbGetImage(index, x * 96, y * 96, (x + 1) * 96, (y + 1) * 96, 1);


Each sprite can then be displayed on the screen using a standard sprite call.

dbSprite(SprNumber, PosX, PosY, imgNumber);


Also, Once you have the images you no longer need the bitmap, so can use dbDeleteBitmap(someNumber) to tidy up a little.
Just remember to add a routine at the end of you program to remove the images created. (I've found that release versions crash if you forget this, but debug versions dont)

Login to post a reply

Server time is: 2024-09-30 19:30:15
Your offset time is: 2024-09-30 19:30:15