void Map::ScrollingMap(int direction, D3DXVECTOR2 pos)
{
static D3DXVECTOR2 last_pos = D3DXVECTOR2(0.0f, 0.0f);
int resy = ((last_pos.y-pos.y)/32);
int resx = ((last_pos.x-pos.x)/32);
m_ScreenOffsetX += resx;
m_ScreenOffsetY += resy;
D3DXVECTOR3 vecEyePt (0.0f, 3.0f, 0.0f);
D3DXVECTOR3 vecLookatPt (m_ScreenOffsetX, m_ScreenOffsetY, 0.0f);
D3DXVECTOR3 vecUpVec (0.0f, 1.0f, 0.0f);
D3DXMATRIXA16 matView;
D3DXMatrixLookAtLH(&matView, &vecEyePt, &vecLookatPt, &vecUpVec);
Engine::GetInstance()->GetGraphicsModule()->GetDevice()->SetTransform(D3DTS_VIEW, &matView);
void Map::Draw()
{
for (int i = 0; i < m_TilesY; i++)
{
for (int j = 0; j < m_TilesX; j++)
{
RECT rect = m_Tiles[j]->GetRect();
D3DXVECTOR3 pos;
pos.x = j*32;
pos.y = i*32;
pos.z = 0;
SpriteObject::GetInstance()->Draw(m_Map, &pos, &rect);
}
}
}
Dynamic scrolling with ID3DXSprite
Hi!
I'm using an ID3DXSprite interface to draw static objects (which don't need transformations) in my game. So my map is drew with this interface.
I want a scrolling like GTA2 : the player is on the center of the screen and the scrolling is dynamic (by pixels not by tiles).
So, I wrote this code, but it didn't work:
How can I do a scrolling by pixels with ID3DXSprite interface ?
Thanks for everything.
EDIT: Another question: How can I implement 'strafing' movement in my game ?
Quote:Original post by Kr00pSDefine "doesn't work". ID3DXSprite is drawn in screen space, it completely ignores all transforms and render states applied. So to do scrolling you'll have to change the offset you pass to Draw() to draw it at a different position.
So, I wrote this code, but it didn't work:
Quote:Original post by Kr00pSBy moving sideways.
EDIT: Another question: How can I implement 'strafing' movement in my game ?
Quote:Define "doesn't work".
The scrolling doesn't work, I move the player and the map doesn't move.
Quote:ID3DXSprite is drawn in screen space, it completely ignores all transforms and render states applied. So to do scrolling you'll have to change the offset you pass to Draw() to draw it at a different position.
Yeah, I tried and it worked but I want a dynamic scrolling (scrolling with pixels according to the player position), not a scrolling by tile.
Quote:By moving sideways.
I know what is strafing movement, but I don't know how to do this in trigonometry.
Thanks for the reply.
Quote:Original post by Kr00pSThen you offset the tiles by individual pixels. ID3DXSprite::Draw takes a position to draw to in pixels, not tiles.
Yeah, I tried and it worked but I want a dynamic scrolling (scrolling with pixels according to the player position), not a scrolling by tile.
Quote:Original post by Kr00pSIt entirely depends on your game. If you have a matrix for the player position and rotation, then strafing is moving along the lateral vector of the matrix, which - assuming a left handed system (E.g. if you're using D3DXMatrixPerspectiveFovLH, etc), it made up from a D3DVECTOR3 from the address of the _11 element of the matrix (I think, at least).
I know what is strafing movement, but I don't know how to do this in trigonometry.
Alternatively, if you know your players direction, take the cross product of that vector and the "up" vector ((0, 0, -1) if you're looking down on the map along the +Z axis) to get the "right" direction.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement