|
-
Mar 31st, 2002, 06:50 AM
#1
Thread Starter
Fanatic Member
Sprites
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!
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Mar 31st, 2002, 11:39 AM
#2
Frenzied Member
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...
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 1st, 2002, 01:25 AM
#3
Thread Starter
Fanatic Member
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:
Code:
03,03,03,08,12,12,12
03,03,03,03,03,12,12
etc. etc.
But then 2 times 13x13.
Then in my program I do this:
VB Code:
imgSprites(0).Picture = LoadPicture("Tree.gif")
imgSprites(1).Picture = LoadPicture("Water.gif")
'etc. etc.
And use this for opening and showing the map:
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
Is this a good way? If not plz suggest something faster and better (and post some code )
Thanx!
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 1st, 2002, 08:14 AM
#4
Frenzied Member
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)
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
that is way better than using picboxes, because you can have transparent backgrounds, you save memory and work.
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 1st, 2002, 08:21 AM
#5
Frenzied Member
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
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 2nd, 2002, 01:43 AM
#6
Thread Starter
Fanatic Member
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
Thanx for the help! 
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:
Code:
0 1 2 3 4 5 6 7 8 9 10 11 12
13 14 15 16 17 18 etc.
So if I make a txt file like I did, the numbers will add a picture to the right image using a single loop.
Thanx again!
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 2nd, 2002, 05:10 AM
#7
Frenzied Member
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)
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 2nd, 2002, 08:13 AM
#8
Thread Starter
Fanatic Member
Ok, thanx!
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 2nd, 2002, 11:52 AM
#9
Thread Starter
Fanatic Member
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?
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 2nd, 2002, 01:36 PM
#10
Frenzied Member
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.
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 3rd, 2002, 05:22 AM
#11
Thread Starter
Fanatic Member
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.
Create dcs? What do you mean?
BTW, with autoredraw set to true it works fine
No matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 3rd, 2002, 08:39 AM
#12
Frenzied Member
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.
Sanity is a full time job
Puh das war harter Stoff!
-
Apr 3rd, 2002, 10:53 AM
#13
Thread Starter
Fanatic Member
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 matter how fool-proof your program is, there will always be a better fool.
Was a post helpful to you? Rate it!
-
Apr 3rd, 2002, 03:33 PM
#14
Frenzied Member
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
Sanity is a full time job
Puh das war harter Stoff!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|