Hi!
I'm making this 2d game in VB, I already got a lot of little 24x24 pix-pics, so what is an easy and fast way to make use of a sprite map, wich control(s) and method(s) do I use?
Thanx!
Printable View
Hi!
I'm making this 2d game in VB, I already got a lot of little 24x24 pix-pics, so what is an easy and fast way to make use of a sprite map, wich control(s) and method(s) do I use?
Thanx!
I am not exactly sure what you mean by "sprite map" if it's just a bunch of coordinates you have to make your own functions to interpret it, but that would be no big deal.
If the game is only going to be some little try I would start out with BitBlt API. It is easy to use and does not require any further API declarations. If you want more than that you can go straight ahead to DirectX. DirectX is not much harder, it just requires a little more code, but once the initialisation is done it basically works the same if you use DirectX 7. (which I would recommend for a pure 2d game anyways, even if people here will tell you that DX8 is just as easy)
well another function that will always be useful is the GetTickCount API, use it to keep things down to a playable speed... (TIMERS ARE EVIL!)
well you don't need any control except a picture box maybe...
Let me explain a little, I'm sure you know the very old 2d adventure game for PC. I'm trying to make something like that. (Like the Pokémon games for Gameboy, but not with Pokémon ofcourse). I though of a way using a lot of Image-controls
I made a big square with two layers of 169 images (13x13). One layer for background and one for foreground. Then I make some text file with codes like:
But then 2 times 13x13.Code:03,03,03,08,12,12,12
03,03,03,03,03,12,12
etc. etc.
Then in my program I do this:
And use this for opening and showing the map:VB Code:
imgSprites(0).Picture = LoadPicture("Tree.gif") imgSprites(1).Picture = LoadPicture("Water.gif") 'etc. etc.
Is this a good way? If not plz suggest something faster and better (and post some code :D )VB Code:
Open "testmap.txt" For Input As #1 For a = 0 To 168 Input #1, n imgFloor(a).Picture = imgSprites(n).Picture Next For a = 0 To 168 Input #1, n imgMap(a).Picture = imgSprites(n).Picture Next Close #1
Thanx! :)
well the way you work your map makes sense but here some suggestions:
don't use txtfiles
just use a 2dimensional array and save it to disk as binary, saves lot's of space and time and code...
than you should use DCs, but if you want to you can use a picbox for every tile, even though a dc only will save memory (needs some more code though)
than you draw the map like
(pseudo code)
that is way better than using picboxes, because you can have transparent backgrounds, you save memory and work.Code:for x = 0 to mapwidth
for y = 0 to mapwidth
BitBlt picGame.hdc, x*tilewidth, y *tileheight, picTiles(map(x,y)).hdc.....
next
next
well maybe that needs a little more explanation:
the thing called map in this code is the two dimensional array storing the map.
map(0,0) represents the top left tile,
you assign numbers to each coordinate and each number represents one pic you want to draw
and I was kind of wondering: you for loops are not nested, how do you want to fill every coordinate by doing it like you did it. maybe I did not look long enough, but it seems like you would get something like that:
Code:111111111 111111111
100000000 111111111
100000000 instead of 111111111
100000000 111111111
100000000 111111111
Thanx for the help! :DQuote:
Originally posted by /\/\isanThr0p
well maybe that needs a little more explanation:
the thing called map in this code is the two dimensional array storing the map.
map(0,0) represents the top left tile,
you assign numbers to each coordinate and each number represents one pic you want to draw
and I was kind of wondering: you for loops are not nested, how do you want to fill every coordinate by doing it like you did it. maybe I did not look long enough, but it seems like you would get something like that:
Code:111111111 111111111
100000000 111111111
100000000 instead of 111111111
100000000 111111111
100000000 111111111
And about my loops, the imgMap's are indexed 0 to 168, 169 images in total wich is 13x13. They're put on the for like this:
So if I make a txt file like I did, the numbers will add a picture to the right image using a single loop.Code:0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15 16 17 18 etc.
Thanx again! :)
alright got you. but I would still look into blting instead of using pictureboxes for that.
www.ur.co.nz the zombie-game tutorial should get you started on Blitting in case you never did it before and don't like the MDSN (which is totally sufficient to learn it, it's not hard at all)
Ok, thanx! :)
Er... If I use BitBlt, the origional images must be visible in order to copy them to the map... That's not what I want... :(
Is there another way, without being able to see the images?
sure if you keep them in picboxes you need to set the autoredraw property to true.
it would be better to just create dcs though.
Create dcs? :confused: What do you mean?Quote:
Originally posted by /\/\isanThr0p
sure if you keep them in picboxes you need to set the autoredraw property to true.
it would be better to just create dcs though.
BTW, with autoredraw set to true it works fine :)
well you can create a dc. (device context) to store the picture in instead of using a picturebox. A picturebox has a dc and a bunch of properties (scalemode for example) and methods (like point and line...) that you don't need and that only take up memory. So you could just create a DC to store the pictue in instead of using a picture box. I think there is a good example on that on fox page but I don't know the url, so you would need to look for it in the forum... or ask someone else.
I found a .cls file on Planet Source Code wich can be used as a dc, but it can only store 1 single dc, for multiple images you need multiple dc's... Too bad, It's back to PictureBox's for me.
But still, thanx for the great help! ;)
no no no :)
you can set up as many dcs as you want (well there is some limitations on memory and stuff...) than you access them via a long (which is a pointer to the dc) you can even put those pointers into an array, so you can access all of that real easy and comfortable