Advertisement

directx9 tutorial

Started by March 17, 2021 11:45 PM
7 comments, last by fleabay 3Β years, 8Β months ago

I am working on a directx9 tutorial, I am able to count down from 255 to 0 which turns the background from bright blue to black however I want to count back up from 0 to 255 which turns the background form black to bright blue. Basically I want to count down and then back up and down again. I know this is a very simple question but I am very new to directx9

int x = 255;

// this is the function used to render a single frame
void render_frame(void)
{
	// clear the window to a deep blue
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, x), 1.0f, 0);

	x--;

	d3ddev->BeginScene();    // begins the 3D scene

	// do 3D rendering on the back buffer here

	d3ddev->EndScene();    // ends the 3D scene

	d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}

So you can bounce a pong ball in 2 dimensions but you can't bounce a variable in 1 dimension?

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

well I have worked on bouncing in one dimension

int x = 255;

// this is the function used to render a single frame
void render_frame(void)
{
	// clear the window to a deep blue
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, x), 1.0f, 0);
	if (x > 0)
	{
	x--;
	}
	else if(x<255)
	{
		x++;
	}
	d3ddev->BeginScene();    // begins the 3D scene

	// do 3D rendering on the back buffer here

	d3ddev->EndScene();    // ends the 3D scene

	d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}

pbivens67 said:
well I have worked on bouncing in one dimension

Cool. So it works?

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

well it counts down but not back up

int upDown = -1; //global like x
x = x + upDown;
if (x <= 0 || x >= 255) upDown = -upDown;

Get rid of the other if else block

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

Advertisement

@fleabay well I got it to work

int move_x =1;
int x = 0;
// this is the function used to render a single frame
void render_frame(void)
{
	// clear the window to a deep blue
	d3ddev->Clear(0, NULL, D3DCLEAR_TARGET, D3DCOLOR_XRGB(0, 0, x), 1.0f, 0);
	x = x + move_x;
	if (x <= 0 || x >= 255)
	{
		move_x = -move_x;
	}

	d3ddev->BeginScene();    // begins the 3D scene

	// do 3D rendering on the back buffer here

	d3ddev->EndScene();    // ends the 3D scene

	d3ddev->Present(NULL, NULL, NULL, NULL);   // displays the created frame on the screen
}

pbivens67 said:
well I got it to work

You should make sure you understand why the if … else block didn't count back up.

πŸ™‚πŸ™‚πŸ™‚πŸ™‚πŸ™‚<←The tone posse, ready for action.

This topic is closed to new replies.

Advertisement