Jump to content
  • Advertisement
Sign in to follow this  
deathknight2005

Problem with 2D Tiles

This topic is 4231 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

I am making a Pacman game from scratch(using my own engine). I stopped working on it for a while and only now began working on it once again and I am stuck with the walls. So now I am attempting tiling, I am tiling the normal ground and the walls, right not the main problem is that they won't draw onto the screen I don't know why. Here is my code(I have ommitted many functions that have nothing to do with my problem, like room wrapping and the movement functions): Sprite.cpp:
#include "Sprite.h"
#include <stdio.h>

char map[20][15] = {
   {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2},
   {2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2}};

   CUSTVERTEX t_vert[] = 
    {
    { 32.0f, 0.0f, 0.0f,1.0f, 0, 0, },
    { 32.0f, 32.0f, 0.0f,1.0f, 0, 1, },
    { 0.0f, 0.0f, 0.0f, 1.0f, 1 , 0, },
    { 0.0f, 32.0f, 0.0f, 1.0f, 1, 1  },
    };

Sprite::Sprite(LPDIRECT3DDEVICE9 d3ddevice, int texWidth, int texHeight, D3DCOLOR col, LPCWSTR filename, HINSTANCE hInst, HWND hwnd)
{
	firstloop = true;
	d3ddev = d3ddevice;
	tWidth = texWidth, tHeight = texHeight;
	tcol = col;
	tfilename = filename;
	iobj = new Input(hInst, hwnd);
	firstTime = true;
	
D3DXIMAGE_INFO d3dxImageInfo;
D3DXIMAGE_INFO d3dxImageInfo2;
D3DXIMAGE_INFO d3dxImageInfo3;
D3DXCreateTextureFromFileEx(d3ddev, L"tiling3.bmp", 
		                         32, 32,
								 1, 
		                         D3DPOOL_DEFAULT,
                                 D3DFMT_UNKNOWN,
                                 D3DPOOL_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
                                 &d3dxImageInfo,
                                 NULL,
                                 &TileTexture);

D3DXCreateTextureFromFileEx(d3ddev, L"tiling4.bmp", 
		                         32, 32,
								 1, 
		                         D3DPOOL_DEFAULT,
                                 D3DFMT_UNKNOWN,
                                 D3DPOOL_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
                                 &d3dxImageInfo2,
                                 NULL,
                                 &TileTexture2);

	D3DXCreateTextureFromFileEx(d3ddev, tfilename, 
		                         tWidth, tHeight,
								 1, 
		                         D3DPOOL_DEFAULT,
                                 D3DFMT_UNKNOWN,
                                 D3DPOOL_DEFAULT,
                                 D3DX_DEFAULT,
                                 D3DX_DEFAULT,
                                 tcol,
                                 &d3dxImageInfo3,
                                 NULL,
                                 &sprTex);

	D3DXCreateSprite(d3ddev, &sprite);
	draw_tiles();
	
}
Sprite::~Sprite(void)
{
	delete iobj;
	SAFE_RELEASE(sprTex);
	SAFE_RELEASE(TileTexture);
	SAFE_RELEASE(TileTexture2);
	SAFE_RELEASE(sprite);
	SAFE_RELEASE(t_buffer);
	SAFE_RELEASE(d3ddev);
	
}

void Sprite::draw_tiles()
{
	d3ddev->CreateVertexBuffer(4*sizeof(t_vert),
                               0,
                               CUSTFVF,
                               D3DPOOL_MANAGED,
                               &t_buffer,
                               NULL);
	void *ptr; 
	t_buffer->Lock(0, sizeof(t_vert), (void**)&ptr, 0);

	memcpy(ptr, t_vert, sizeof(t_vert));

	t_buffer->Unlock();

	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0,0,255), 1.0f, 0);
    d3ddev->BeginScene();
/*for (ty = 0; ty < WORLD_SIZEY; ty++)
   {
      for (tx = 0; tx < WORLD_SIZEX; tx++)
      {
         tile = map[ty][tx];    // tile now stores the ID of this particular tile
         tile_src.left    =  (tile-1)*TILE_SIZE;
         tile_src.top     =  0;
         tile_src.right   =  tile * TILE_SIZE;
         tile_src.bottom  =  TILE_SIZE;
	  }
}*/
for (ty = 0; ty < WORLD_SIZEY; ty++)
   {
      for (tx = 0; tx < WORLD_SIZEX; tx++)
      {
		d3ddev->SetStreamSource(0, t_buffer, 0, sizeof(CUSTVERTEX));
        d3ddev->SetFVF(CUSTFVF);
		if(tile == 1) 
		{
        d3ddev->SetTexture(0, TileTexture);
		}
		else
		{
		d3ddev->SetTexture(0, TileTexture2);
		}
		D3DXMatrixTranslation(&matTranslate, tx * TILE_SIZE, ty * TILE_SIZE, 0.0f); 
		d3ddev->SetTransform(D3DTS_WORLD, &matTranslate);
		d3ddev->DrawPrimitive(D3DPT_TRIANGLESTRIP, 0, 2);
      }
   }
 d3ddev->EndScene();
 d3ddev->Present(NULL, NULL, NULL, NULL);

}

It is the last function in the above code that is meant to draw the tiles.

Share this post


Link to post
Share on other sites
Advertisement
Are you using the debug runtimes? If so, any relevant debug output? If not, why not?
Have you tried rendering without textures?
Have you tried rendering without lighting?
Have you tried rendering without cullung?
Have you tried using DrawPrimitiveUP to render a single triangle in the middle of the view? Does that show up?
Are your view and projection matrices set up correctly? Are you sure?
Have you tried using transformed vertices (D3DFVF_XYZRHW)?

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!