Jump to content
  • Advertisement
Sign in to follow this  
Kr00pS

Dynamic scrolling with ID3DXSprite

This topic is 3721 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

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:
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);
		}
	}
}


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 ?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Kr00pS
So, I wrote this code, but it didn't work:
Define "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.

Quote:
Original post by Kr00pS
EDIT: Another question: How can I implement 'strafing' movement in my game ?
By moving sideways.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kr00pS
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.
Then you offset the tiles by individual pixels. ID3DXSprite::Draw takes a position to draw to in pixels, not tiles.

Quote:
Original post by Kr00pS
I know what is strafing movement, but I don't know how to do this in trigonometry.
It 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).

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.

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!