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 / Tile Mapping in Dark GDK

Author
Message
martianxx
13
Years of Service
User Offline
Joined: 19th Feb 2011
Location:
Posted: 9th Jun 2011 22:26
Hi, I am quite new to Dark GDK and C++ in general but I have decided to spend my time trying to learn it in a project that I plan to spend my summer doing. My aim is to create a side scrolling platform game (or at least 1 working level that can be expanded on). After looking over these forums for ideas i read a sticky on the 2D forum by zenassem about 2D principles and spent some time reading the section on using arrays to add tiles to your game. To try and work out how I was going to use this technique to make my levels I started playing around in visual studio. I created an array with two dimensions called Map and... well here is the code I was using, easier to see than explain.



The images are just flat colour .png files of 32x32 pixels. When I did this I only got the bottom right corner coloured in and was curious as to why. After soe fiddling around I realised that I was repositioning the image rather than creating a new one. IE when x and y are 0 I place the sprite in position 0,0 and when x and y are 1 i move the same sprite to 32,32 rather than adding the same image to that area as well as 0,0. SO the question is asking how can I do it to reuse an image, the alternative I see is loading the image multiple times giving seperate image IDs but that would be silly in a game with berphaps 100 tiles on screen or more. By the way the screen is set to 64x64 with dbSetDisplayMode. If i can get this to work as intended I play to use a XML document to save the level on and read into an array using TinyXml. Thanks in advance. David
Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 10th Jun 2011 01:43
You just need the one image but you create multiple sprites which use the same image.

You may have 2 images and 100 sprites.

martianxx
13
Years of Service
User Offline
Joined: 19th Feb 2011
Location:
Posted: 10th Jun 2011 03:52
thanks for a quick response, after quite a bit more searching I see I could store both the tiles in one file and copy parts of the image into the sprite, but yes i see what you mean more like blue sprites would be where image ID 1 is the "blue.png" file

dbSprite(1, 0, 32, 1)
dbSprite(2, 32, 32, 1)
dbSprite(3, 64, 32, 1)

David
Dashiznitz
13
Years of Service
User Offline
Joined: 25th May 2011
Location:
Posted: 17th Jun 2011 19:58
Use this... get the Gaddis C++ book. That's what I used. Had a lot of examples.

dbLoadImage("Grass.bmp", GRASS);
dbLoadImage("Path.bmp", PATH);.... etc with all sprites.

int tileMap[TILE_ROWS][TILE_COLS] =
{ {GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, PATHNW, PATH, PATH },
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, PATH, GRASS, GRASS},
{PATH, PATH, PATH, PATH, PATHNE, GRASS, GRASS, PATH, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, PATH, GRASS, GRASS, PATH, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, PATHSW, PATH, PATH, PATHSE, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS},
{GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS, GRASS}
};

// Variables for the tile coordinates
int x = 0, y = 0;

// Display all the tiles specified in the map.
for (int r = 0; r < rows; r++)
{
// Set x to 0.
x = 0;

// Display all the tiles in this row.
for (int c = 0; c < TILE_COLS; c++)
{
dbPasteImage( map[r][c], x, y );
x += TILE_WIDTH;
}

// Increase y for the next row.
y += TILE_HEIGHT;
}
}

Get that book.. it helps a lot with using the most basic darkGDK functions... it is teaches basic C++ using the DarkGDK library... more fun than learning c++ using cin/cout and text files.

-Trying to get better
Oster200
13
Years of Service
User Offline
Joined: 21st Jan 2011
Location:
Posted: 18th Jun 2011 00:13 Edited at: 18th Jun 2011 00:13
You could also look at htis webpage: http://www.darkgdk.us/index.php?page=6 this webpage talks about tilesets

Login to post a reply

Server time is: 2024-10-02 17:28:59
Your offset time is: 2024-10-02 17:28:59