我自己做了个纹理,每frame的大小是40*40,但是在代码中,要正确绘制每个frame,left与right,top与bottom的差都必须设为64,这是什么原因?我使用40就得不到完整的那个frame,导致动画错误
解决方案 »
- vc++ oracle数据库查询问题?
- 关于结束进程的问题,高手请进。
- 100分求做一个对话框,用ADO连接SYSBASE,做个连通测试
- 大家知道有什么控件可以生成曲线图。
- 程序release和debug的问题
- 请问一下国外VC开源的控件(组件)网站有哪些?
- 请问C++.obj是??
- “CSendPacketHelper”中没有找到重载的成员函数
- 谁有类似Acdc那样可以显示bmp图片缩略图的原码?或者告诉我应该怎么做?
- 如何通过程序取得局域网上所有机器?
- 用 ActiveX Script 执行 VBScript 脚本遇到问题
- 新手请教 VC2005 MFC 如何为一个按钮添加 MouseMove消息?
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; drawRect.left = 1*64;
drawRect.right = 1*64+64; drawRect.top= 0; drawRect.bottom=drawRect.top+64; D3DXVECTOR3 pos;
if(count != 0)
posX += 16;
if(posX > 800)
posX -= 800;
pos.x = posX;
if(count ==0||count == 4)
{
pos.y = 100 ;
}
else if(count == 1|| count == 3)
{
pos.y = 100 - 8;
}
else if(count == 2)
{
pos.y = 100 - 12;
}
pos.z = 0; // 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(); // Finished rendering
gD3dDevice->EndScene();
gD3dDevice->Present(NULL,NULL,NULL,NULL);
count++;
}
}/**************************************************************************************************
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)); presParams.Windowed=TRUE;
presParams.SwapEffect=D3DSWAPEFFECT_DISCARD;
presParams.BackBufferFormat=D3DFMT_UNKNOWN;
presParams.BackBufferCount=1; // 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",&gTexture);
return TRUE;
}
void UpdateWorld(HWND hWnd)
{
DWORD timeNow=timeGetTime();
if (timeNow-lastUpdate>kTimeBetweenUpdated)
{
act = TRUE;
lastUpdate=timeNow;
}
}