Recommended Posts

I'm trying to draw frames from a strip loaded, but it draws more than 1 frame. Each frame is 64X64, but 3 frames are squished together in a 64x64 rectangle. loading:
[SOURCE]
switch (player_index)
{
case 0:
player_sprite_dir="img/sonic.png";
break;
case 1:
player_sprite_dir="img/tails.png";
break;
case 2:
player_sprite_dir="img/knuckles.png";
break;
}
D3DXIMAGE_INFO d3dxImageInfo;

D3DXGetImageInfoFromFile(player_sprite_dir, &d3dxImageInfo);
player_sprite_width=d3dxImageInfo.Width;
player_sprite_height=d3dxImageInfo.Height;

D3DXCreateTextureFromFileEx( D3DDEVICE9,
player_sprite_dir,
player_sprite_width,
player_sprite_height,
1,
D3DPOOL_DEFAULT,
D3DFMT_UNKNOWN,
D3DPOOL_DEFAULT,
D3DX_DEFAULT,
D3DX_DEFAULT,
D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
&d3dxImageInfo,
NULL,
&player_texture );

D3DDEVICE9-&gt;SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
D3DDEVICE9-&gt;SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
D3DXCreateSprite( D3DDEVICE9, &player_sprite );
[/SOURCE]
RECT:
[SOURCE]
RECT srcRect;
srcRect.top    = 0;
srcRect.left   = player_image_index*64;
srcRect.bottom = srcRect.top+64;
srcRect.right  = srcRect.left+64;
[/SOURCE]
Do I have to turn something extra on or is it just user error? [Edited by - justin12343 on February 19, 2010 3:23:36 PM]

Share on other sites
Quote:
 Do I have to turn something extra on or is it just user error?

Can't tell from the code you posted as there's no code for the actual drawing.
Quote:
 3 frames are squished together

"Squished" is a rather untechnical term. Can you describe in a bit more detail what you're trying to display and what is looks like? Along with the code, maybe an image?

Your rectangle for accessing frames 0, 1 and 2 could work for accessing the individual parts of a 192x64 image. Need to see how you draw them.

Share on other sites
Also, please use the "source" or "code" tags when posting source code so that it gets proper formatting. See the FAQ.

Share on other sites
Also, please use the "source" or "code" tags when posting source code so that it gets proper formatting. See the FAQ.

Share on other sites
here's the drawing part:

    D3DXVECTOR3 vCenter( 0.5f, 0.5f, 0.0f );    D3DXVECTOR3 vPosition( x, y, z );    player_sprite->Begin( D3DXSPRITE_ALPHABLEND );    player_sprite->Draw( player_texture,                          &srcRect,                          &vCenter,                          &vPosition,                          D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );    player_sprite->End();

It's supposed to draw a what frame player_image_index is set to (player_image_index=0 then draw the first frame).

For some reason it does this:
screen shot

[Edited by - justin12343 on February 21, 2010 11:26:28 AM]

anyone

Share on other sites
I guess no one is going to answer.

Share on other sites
In your draw call, leave the center position NULL and change just the position. I'm still not sure what you want the result to look like, but you can play around with vPosition.
player_sprite->Draw( player_texture, &srcRect, NULL, &vPosition,  D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );

Share on other sites
Quote:
 Original post by BuckeyeIn your draw call, leave the center position NULL and change just the position. I'm still not sure what you want the result to look like, but you can play around with vPosition. player_sprite->Draw( player_texture, &srcRect, NULL, &vPosition, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );

that didn't work, it's still drawing 3 frames together in the quad.

I trying to get it look like this:
screen shot
screen shot

Share on other sites
Are you trying to draw three separate images, each of which is 64x64, in three separate locations? If so, vertically or horizontally?

If 3 separate images, vertically:
D3DXVECTOR3 pos(0,player_image_index*64,0);sprite->Draw(texture,NULL,NULL,&pos,D3DCOLOR..);

If that doesn't work, draw just one of the textures and try to determine where the problem is.

Share on other sites
I'm just trying to draw a animated sprite. every time I try to draw a single frame, it draws three frames bunched up (untechnical term) together.

Share on other sites
Previous post:
Quote:
 draw just one of the textures and try to determine where the problem is ... sprite->Draw(texture,NULL,NULL,&pos,D3DCOLOR..);

This results in all 3 separate images rendering together when called for just a single index?

Share on other sites
yes.

I been trying to figure this out.

Share on other sites
Post your revised code and let's take a look.

Create an account

Register a new account

• Partner Spotlight

• Forum Statistics

• Total Topics
627665
• Total Posts
2978524

• 10
• 10
• 12
• 22
• 13