主题:[原创]求救D3D9编程,高手进
我现在要写一个力量槽,显示力量由小变大,我没有好的办法,我把我的方法写出来,高手请帮我改改..[em19]
CMiniMap::CMiniMap(void):g_pIB(NULL),g_pVB(NULL)
{
[color=FF0000]m_miniPowerStartX[/color]=550;
}
CMiniMap::SetPower(int power)
{
[color=FF0000]m_miniPowerStartX[/color] = power;
}
HRESULT CMiniMap::OnCreate()
{
UINT w = DXUTGetBackBufferSurfaceDesc()->Width, h = DXUTGetBackBufferSurfaceDesc()->Height;
RenderVertex rv[] = {
{w-200, 2.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f ,0.7f, 0.5f)},//0
{w-5, 2.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f, 0.7f, 0.5f)},//1
{w-200, 150.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f, 0.7f, 0.5f)},//2
{w-5, 150.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f, 0.7f, 0.5f)},//3
{w-200, 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//4
{600.0f, 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//5
{w-200, 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//6
{600.0f, 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//7
{w-200, 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)},//8
{[color=FF0000]m_miniPowerStartX[/color], 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)},//9
{w-200, 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)},//10
{[color=FF0000]m_miniPowerStartX[/color], 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)}//11
};
if (FAILED(g_pDevice->CreateVertexBuffer(sizeof(rv), 0, FVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &g_pVB, NULL)))
{
return E_FAIL;
}
byte * pbyData;
if (FAILED(g_pVB->Lock(0, sizeof(rv), (void**)&pbyData, 0)))
{
return E_FAIL;
}
memcpy(pbyData, rv, sizeof(rv));
g_pVB->Unlock();
WORD idx[] = {0,1,2,2,1,3,4,5,6,6,5,7,8,9,10,10,9,11};
if (FAILED(g_pDevice->CreateIndexBuffer(sizeof(idx), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &g_pIB, NULL)))
{
return E_FAIL;
}
byte* byData;
g_pIB->Lock(0, sizeof(idx), (void**)&byData, 0);
memcpy(byData, idx, sizeof(idx));
g_pIB->Unlock();
return D3D_OK;
}
上面是我的初始化顶点,在GAME主类中调用
先创建了CGame的对象m_pMiniMap;
HRESULT CGame::OnCreate()
{
m_pMiniMap.OnCreate();
}
void CGame::OnFrameMove(float fTime)
{
m_pMiniMap.SetPower(int(fTime*2000)%200)//力量槽长度为200,让它在0到200之间动
}
这样被我做死了,画的力量槽动不了,后来我改了以下方法,把创建顶点写到OnFrameMove里面.
void CGame::OnFrameMove(float fTime)
{
m_pMiniMap.SetPower(int(fTime*2000)%200)
m_pMiniMap.OnCreate();
}
这样就会不停的创建,资源会耗尽,每秒的贞数一会就下降了,可是我想不出别的办法
谁救救我啊!!
CMiniMap::CMiniMap(void):g_pIB(NULL),g_pVB(NULL)
{
[color=FF0000]m_miniPowerStartX[/color]=550;
}
CMiniMap::SetPower(int power)
{
[color=FF0000]m_miniPowerStartX[/color] = power;
}
HRESULT CMiniMap::OnCreate()
{
UINT w = DXUTGetBackBufferSurfaceDesc()->Width, h = DXUTGetBackBufferSurfaceDesc()->Height;
RenderVertex rv[] = {
{w-200, 2.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f ,0.7f, 0.5f)},//0
{w-5, 2.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f, 0.7f, 0.5f)},//1
{w-200, 150.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f, 0.7f, 0.5f)},//2
{w-5, 150.0f, 0.0f, 1.0f, D3DXCOLOR(0.7f, 0.7f, 0.7f, 0.5f)},//3
{w-200, 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//4
{600.0f, 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//5
{w-200, 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//6
{600.0f, 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,1.0f,0.0f,0.3f)},//7
{w-200, 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)},//8
{[color=FF0000]m_miniPowerStartX[/color], 160.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)},//9
{w-200, 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)},//10
{[color=FF0000]m_miniPowerStartX[/color], 170.0f, 0.0f, 1.0f, D3DXCOLOR(1.0f,0.0f,0.0f,0.5f)}//11
};
if (FAILED(g_pDevice->CreateVertexBuffer(sizeof(rv), 0, FVF_CUSTOMVERTEX, D3DPOOL_MANAGED, &g_pVB, NULL)))
{
return E_FAIL;
}
byte * pbyData;
if (FAILED(g_pVB->Lock(0, sizeof(rv), (void**)&pbyData, 0)))
{
return E_FAIL;
}
memcpy(pbyData, rv, sizeof(rv));
g_pVB->Unlock();
WORD idx[] = {0,1,2,2,1,3,4,5,6,6,5,7,8,9,10,10,9,11};
if (FAILED(g_pDevice->CreateIndexBuffer(sizeof(idx), 0, D3DFMT_INDEX16, D3DPOOL_MANAGED, &g_pIB, NULL)))
{
return E_FAIL;
}
byte* byData;
g_pIB->Lock(0, sizeof(idx), (void**)&byData, 0);
memcpy(byData, idx, sizeof(idx));
g_pIB->Unlock();
return D3D_OK;
}
上面是我的初始化顶点,在GAME主类中调用
先创建了CGame的对象m_pMiniMap;
HRESULT CGame::OnCreate()
{
m_pMiniMap.OnCreate();
}
void CGame::OnFrameMove(float fTime)
{
m_pMiniMap.SetPower(int(fTime*2000)%200)//力量槽长度为200,让它在0到200之间动
}
这样被我做死了,画的力量槽动不了,后来我改了以下方法,把创建顶点写到OnFrameMove里面.
void CGame::OnFrameMove(float fTime)
{
m_pMiniMap.SetPower(int(fTime*2000)%200)
m_pMiniMap.OnCreate();
}
这样就会不停的创建,资源会耗尽,每秒的贞数一会就下降了,可是我想不出别的办法
谁救救我啊!!