[Quote=引用 1 楼 tkminigame 的回复:]
你可以把图片做成64*64,然后在设置顶点uv的时候设置到40的位置,不是1.0.
[/Quote]
不是太懂,这个1.0是在哪里设的?下面是我的代码
void Render()
{
// Clear the back buffer
HRESULT hr=gD3dDevice->Clear(0,NULL,D3DCLEAR_TARGET,D3DCOLOR_XRGB(0,255,0),1.0f,0);
if (FAILED(hr))
return;
// Begin the scene
hr=gD3dDevice->BeginScene();
if (SUCCEEDED(hr))
{
// Draw with alpha blending - needed for our transparent sprites
gSprite->Begin(D3DXSPRITE_ALPHABLEND);
if(count == 5)count=0;
// Now draw all the cavemen, fill a rect to select the area of the texture to draw
for (int i=0;i<kNumCavemen;i++)
{
RECT drawRect;
// This is the other method of using the sprite interface. We do not set a matrix
// transformation but just use the parameters to pass in the position. This is fine
// when we do not need to rotate or scale the graphic
gSprite->Draw(gTexture,&drawRect,NULL,&pos,0xffffffff);
}
// Finished drawing. By reusing the same sprite object D3D can maximise batching of the draws
gSprite->End();
/**************************************************************************************************
Desc: To initialise DirectX we must create the Direct3D object and then a device
**************************************************************************************************/
bool InitialiseDirectX(HWND hWnd)
{
// Create the D3D object
gD3dObject=Direct3DCreate9(D3D_SDK_VERSION);
if (gD3dObject==NULL)
return FALSE;
// Fill out some presentation parameters for running in a window
D3DPRESENT_PARAMETERS presParams;
ZeroMemory(&presParams,sizeof(presParams));
// Create the D3D device
HRESULT hr=gD3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_HARDWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);
if (FAILED(hr))
{
// Some cards may not do hardware vertex processing so fall back to software:
hr=gD3dObject->CreateDevice(D3DADAPTER_DEFAULT,D3DDEVTYPE_HAL,hWnd,
D3DCREATE_SOFTWARE_VERTEXPROCESSING, &presParams, &gD3dDevice);
if (FAILED(hr))
return FALSE;
}
return TRUE;
}
/**************************************************************************************************
Desc: Our application is finishing so we must clean up by deallocating any DirectX objects
Evey DirectX object has a release function to call
**************************************************************************************************/
void CleanupDirectX()
{
if (gTexture)
gTexture->Release();
if (gSprite)
gSprite->Release();
if (gD3dObject)
gD3dObject->Release();
if (gD3dDevice)
gD3dDevice->Release();
}
/**************************************************************************************************
Desc: Create our sprite object. Return FALSE if an error occured.
Note: We only use one sprite object as this is the most efficient way of doing it. The sprite object
is purely a mechanism for drawing 2D graphics. By using just one and doing all our drawing between
begin and end Direct3D can batch the rendering of the textures most efficiently
**************************************************************************************************/
bool CreateSprite()
{
HRESULT hr=D3DXCreateSprite(gD3dDevice,&gSprite);
if (FAILED(hr))
return FALSE;
// Load a cavemen texture
D3DXCreateTextureFromFile(gD3dDevice,"d:\\slime.tga",>exture);