Jump to content
  • Advertisement
Sign in to follow this  
farhanx

ID3DXSprite is not working?

This topic is 4969 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 new doing 2d work on directX8 so need some guide from you ppls... here is my code i dont know what is missing , just its not showing anything on the screen accept my purple screen D3DXCreateTextureFromFile(dDevice,"pics.bmp",&texture); D3DXCreateSprite(dDevice,&pSprite); RECT SrcRect; SrcRect.bottom=200; SrcRect.left=0; SrcRect.right=300; SrcRect.top=400; dDevice->SetRenderState(D3DRS_LIGHTING,FALSE); while(TRUE) { dDevice->Clear(0,0,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,0,55),0.0f,0); dDevice->BeginScene(); dDevice->SetTexture(0,texture); pSprite->Draw(texture,&SrcRect, &D3DXVECTOR2(11.0f,33.0f),NULL,0.0f, &D3DXVECTOR2(1.0f,2.0f),D3DCOLOR_RGBA(255,255,255,127)); dDevice->EndScene(); dDevice->Present(0,0,0,0); ................ I have changes source rect values , scale values, Axis values butt nothing works?? help....

Share this post


Link to post
Share on other sites
Advertisement
Try calling pSprite->Begin() just before you call pSprite->Draw().
Call pSprite->End() just after you draw the sprite.

Use appropriate flags when calling pSprite->Begin().For instance if you want alpha blending specify D3DXSPRITE_ALPHABLEND.

Also, it's best to get into the habit of checking your HRESULTS.
In this particular case make sure you check the HRESULT from your D3DXCreateTextureFromFile call.

HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
Is there a way to scale sprites? I Haven't been able to.. they just seem to be as large as the texture you use (32x32 or whatever)

Share this post


Link to post
Share on other sites
As far as I know, ID3DXSprite itself doesn't provide anything for scaling - I'm wondering if there's nothing you can do using the texture transform matrix, though.

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeyO
Is there a way to scale sprites? I Haven't been able to.. they just seem to be as large as the texture you use (32x32 or whatever)


Have you tried using the D3DXSPRITE_OBJECTSPACE flag when you call ID3DXSprite::Begin()

Here is a quote from the SDK Docs regarding this flag
Quote:

The world, view, and projection transforms are not modified. The transforms currently set to the device are used to transform the sprites when the batched sprites are drawn (when ID3DXSprite::Flush or ID3DXSprite::End is called). If this flag is not specified, then world, view, and projection transforms are modified so that sprites are drawn in screen-space coordinates.


HTH,
Cambo_frog

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeyO
Well, what if you do want to draw the sprites in screen space?


If you use the D3DXSPRITE_OBJECTSPACE flag, you would probably have to set your view and projection matrices to map your coordinates to screen space prior to calling ID3DXSprite::Begin().

Maybe you could avoid this by using the ID3DXSprite::SetTransform() method, but I am not sure how this method works, as The SDK documentation is very limited regarding this.For instance I am not sure if you have to call this method between ID3DXSprite::Begin() and ID3DXSprite::End().

Which method(s) have you tried to scale the sprite so far?

TIA,
Dave

Share this post


Link to post
Share on other sites
Only transform.

If you change the scale of the rectangle during the draw method, it will change the size of the rectangle, but not the size of the texture drawn within the rectangle.

Share this post


Link to post
Share on other sites
Quote:
Original post by MikeyO
Only transform.

If you change the scale of the rectangle during the draw method, it will change the size of the rectangle, but not the size of the texture drawn within the rectangle.


I am sure we can get to the bottom of this eventually :)
Could you please give me some more info?

1) When you say "Only transform", I assume you mean ID3DXSprite::SetTransform(), is this correct?

2) Assuming you are using ID3DXSprite::SetTransform(), do you call this method between ID3DXSprite::Begin() and ID3DXSprite::End() or before ID3DXSprite::Begin(), or have you tried both?

3) Could you post your code?

Maybe the only way is to use the D3DXSPRITE_OBJECTSPACE flag in the call to ID3DXSprite::Begin() and set the view and projection matrices to map your coordinates to screen space prior to calling ID3DXSprite::Begin()?

I can post code on how to set up your view and projection matrices to map to screen space, but it is probably best if you could give me the answers to questions 1 to 3 first.

TIA,
Cambo_frog


Share this post


Link to post
Share on other sites
1) Yes.. but not SetTransform(), there is a read/set Transform property

2) Im doing transform after Begin() and before Draw()

3) (I'm using C#/MDX)
flareTest.Begin(SpriteFlags.SortTexture | SpriteFlags.ObjectSpace);

Sprite.Transform = Matrix.Scaling(0.02f, 0.02f, 0.02f);

Sprite.Draw(Texture, new Rectangle(0, 0, 32, 32), new Vector3(16, 16, 0), new Vector3(0, 0, 0), Color.Gray);

flareTest.End();

So, to 'Add a sprite to the list of batched sprites.', I need to call Draw(), but for each sprite do I need to do a Begin() and End()? If each End() call 'Restores the device to the state it was in before', wouldnt doing Begin() and End() for each sprite be inefficient?

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!