Jump to content
  • Advertisement
Sign in to follow this  
jagguy

move around a map

This topic is 4375 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If I have a pre-rendered 2D map of say 4 screen lengths, and want to move a sprite around the map on the screen, without walking on certain places eg rocks. So I need tomove the map on the screen in different directions. Is there a standard way to do this or is it more open to the programmer. Currently I can do this with a blotchy movement of 32 bits per move of the map, and it is taking nearly 1000 lines to do. I am splitting a map into tiles and having a sprite walk around without hitting things on the map. I haven't even started to make it OO which I doubt will change the prog length of about 1000 lines. Is there a standard way to do this problem in shorter code length?

Share this post


Link to post
Share on other sites
Advertisement
Firstly, it depends on the API you use. Do you use DirectX? OpenGL? SDL? Allegro? Windows GDI?

Secondly, we need to know, in a nutshell, how your drawing works. Do your sprites consist of textured polygons that you move with transformation matrices? Or do you copy pixel data from an image to the screen/back buffer? If the latter, it may be more difficult to achieve smooth scrolling.

Share this post


Link to post
Share on other sites
Sorry i didn't say i was using directx/c++ 'is there any other more professional tool?

I am getting about 500-600 frames per second with a large map and 1 sprite
Also I am using the sprite interface .

Share this post


Link to post
Share on other sites
Since (in other posts) I've already tried to explain how to use a map structure and draw your tiles from this each frame on the fly, I assume this is not the approach you want.

Could you post your existing drawing code so we can get more of an idea about what you are trying to do?

Share this post


Link to post
Share on other sites
Quote:
Original post by EasilyConfused
Since (in other posts) I've already tried to explain how to use a map structure and draw your tiles from this each frame on the fly, I assume this is not the approach you want.

Could you post your existing drawing code so we can get more of an idea about what you are trying to do?


Hi and thanks for your help so far, I do appreciate it.

I had a more specific question this time so i thought I ask another one. I was hoping for a standard method and a tutorial to look up but if there isn't one I will have to make do.
A large pre-rendered map that a sprite moves around ,the map scrolls and the sprite interacts with the map.
Let me tinker a little further so I can ask better questions.

Share this post


Link to post
Share on other sites
I think you are complicating a simple problem. To move sprites (or any other objects) around simple keep track of a transformation matrix for that sprite. This transformation matrix can include as little information as the x,y,z position of the sprite or as complex as scalling and rotation as well.

When rendering simple translate your sprite by this transformation.


NOW For the camera. If you want the camera to follow a sprite simple called that sprites transformation first followed by your rendering commands.

IF you are not using the built in matrix functionality of your 3D API then something like this will suffice.

RenderMap(offsetx,offsety)
{
for (x->0 to mapsizex)
for (y->0 to mapsizey)
RenderTile(x+offsetx,y+offsety)
}

And the same applies for your sprite

RenderSprite(offsetx,offsety)
{
this->Sprite.Render(this->x+offsetx,this->y+offsety);
}

Share this post


Link to post
Share on other sites
Quote:
Original post by dawidjoubert
I think you are complicating a simple problem. To move sprites (or any other objects) around simple keep track of a transformation matrix for that sprite. This transformation matrix can include as little information as the x,y,z position of the sprite or as complex as scalling and rotation as well.

When rendering simple translate your sprite by this transformation.


NOW For the camera. If you want the camera to follow a sprite simple called that sprites transformation first followed by your rendering commands.

IF you are not using the built in matrix functionality of your 3D API then something like this will suffice.

RenderMap(offsetx,offsety)
{
for (x->0 to mapsizex)
for (y->0 to mapsizey)
RenderTile(x+offsetx,y+offsety)
}

And the same applies for your sprite

RenderSprite(offsetx,offsety)
{
this->Sprite.Render(this->x+offsetx,this->y+offsety);
}


well i think I am already doing this. Each map tile has a position in a 1D structure, including the row and col it appears in the map. Go through 2 for loops and start displaying the 1d array with the map , as you just do some maths to get to the startrow,col in the array then print to screen from 0,0.

Share this post


Link to post
Share on other sites
I am getting now the problem of reading in a map 640 X 640 pixels, with each tile 32 pixels.
So I should have 200 tiles of 32 pixel X 32 pixels..
When i print out all the tiles I don't get the whole map but it looks like 2/3 of it. It looks like the map has been scaled up when reading in so i am confused, does anyone have an idea?
I read in like this


if (FAILED(hr= D3DXCreateTextureFromFile(g_pd3dDevice,
L"grass3.bmp",&g_BackGroundFile)))
return hr;

i=0;
for (int row=0; row < bRows; row++)
for (int col=0; col < bCols; col++)
{
g_back.Col = col;
g_back.Row = row;
g_back.xMapPos =col * 32;
g_back.yMapPos =row * 32;
g_back.CanMoveOnTile =true;
g_back.TilePixelHeight =32;
g_back.TilePixelWidth =32;
g_back.TileNumber =i;
g_back.TileType =1;

i++;
}

/////print out like this
count=0;
for (int j=0; j< screenRows;j++)
for (int i=0; i< screenCols;i++)

{
{

backRect.left=g_back[count].xMapPos ;
backRect.right=backRect.left+g_back[count].TilePixelWidth ;
backRect.top=g_back[count].yMapPos ;
backRect.bottom=backRect.top+g_back[count].TilePixelHeight ;


D3DXVECTOR3 pos2=D3DXVECTOR3(
i * 32 ,
j * 32 , 1);
g_Sprite->Draw(g_BackGroundFile,&backRect,NULL,&pos2,0xFFFFFFFF);

count+=1;

of course I should only get a 640 X 480 map on the screen due to the window size but it looks like it is about 380 X 400 of the actual mapsize.

Share this post


Link to post
Share on other sites
I had a look at the articles and can do what it says but here is a problem.
If you want smooth scrolling of a tiled map without a constant move ( and not really slow), you need to move the map a varying amount at a time or small amount a time (less than tile size).

This is where it gets tricky as i do now have a smooth scrolling map but you need extra code to move a less than a tile size.

eg 32 * 32 tile size or half that wont move smoothly at a constant each time.
Moving the map at 4 -32 pixels a time depending if you want to move fast or just a bit looks better.

If I move a map down i need to program an extra row to be drawn at the top.

Does anyone have a better logic for real time movement of a smooth scrolling map?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!