Sign in to follow this  
techboy123

Problem displaying sprites

Recommended Posts

techboy123    122
I've been having trouble displaying tiles and sprites with D3DXSprite. The very first tile seems to work fine but when i move onto the other tiles it starts displaying the wrong parts. The image below shows what happens and the sprite sheet Tile trouble and here is the source code which draws the map
[for(i2 =0; i2<12; i2++)
	{
		for(i1 =0; i1<16; i1++)
	    {
			Tile_Selected = Map[i2][i1];
			SetRect(&rect, 64*Tile_Selected, 0, rect.left + 64, 64);
			TileDraw.x = (i1*64);
	        TileDraw.y = (i2*64);
	        TileDraw.z = 1.0f;
			Sprite->Draw(Image,&rect,NULL, &TileDraw,0xFFFFFFFF);
		}
	}


Share this post


Link to post
Share on other sites
galapogos22    385
Try changing the line ....

SetRect(&rect, 64*Tile_Selected, 0, rect.left + 64, 64);

to

SetRect(&rect, 64*Tile_Selected, 0, (64*Tile_Selected) + 64, 64);

or

rect.left = 64*TileSelected; //note ordering
rect.right = rect.left + 64;
rect.top = 0;
rect.bottom = 64;

....as it may be that in seting the right value based on the left value while still inside the SetRect function may be basing the right value on an old or wrong left value. Just because the left value is first in the parameter list does not mean it is set first and besides you are passing a pointer to rect and then a rect parameter in the same function parameter list so it looks... untidy.

Share this post


Link to post
Share on other sites
techboy123    122
Didn't work. however thanks for the help, your method does look nicer, is there any bugs in D3DXSprite that might be causing this

[Edited by - techboy123 on April 20, 2008 2:55:25 PM]

Share this post


Link to post
Share on other sites
Cantos    212
By default textures must be loaded with dimensions in power of 2 sizes. (64,128,256,512). Change the canvas size of your image to 512x64. (Just add space for two more tiles).

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this