Results 1 to 14 of 14

Thread: Sprites

  1. #1

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719

    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!

  2. #2
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  3. #3

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    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:
    1. imgSprites(0).Picture = LoadPicture("Tree.gif")
    2. imgSprites(1).Picture = LoadPicture("Water.gif")
    3. 'etc. etc.
    And use this for opening and showing the map:
    VB Code:
    1. Open "testmap.txt" For Input As #1
    2.     For a = 0 To 168
    3.          Input #1, n
    4.          imgFloor(a).Picture = imgSprites(n).Picture
    5.     Next
    6.     For a = 0 To 168
    7.          Input #1, n
    8.          imgMap(a).Picture = imgSprites(n).Picture
    9.     Next
    10. 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!

  4. #4
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  5. #5
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  6. #6

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    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!

  7. #7
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  8. #8

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    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!

  9. #9

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    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!

  10. #10
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  11. #11

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    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!

  12. #12
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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!

  13. #13

    Thread Starter
    Fanatic Member arsmakman's Avatar
    Join Date
    Dec 2001
    Location
    Leiden, Netherlands.
    Posts
    719
    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!

  14. #14
    Frenzied Member /\/\isanThr0p's Avatar
    Join Date
    Jul 2000
    Location
    They can't stop us! We're on a misson from God.
    Posts
    1,181
    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
  •  



Click Here to Expand Forum to Full Width