Public Group

# little help

This topic is 2562 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am trying to get my ball to move around the screen and bounce off the edges.
[font="Consolas"][font="Consolas"]D3DXVECTOR3 vecPos_ball = D3DXVECTOR3(ball,400,0);

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](ball==0)

{

i=1;

}

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]else[/font][/font][/font][font="Consolas"][font="Consolas"] [/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"](ball==780)

{

i=-1;

}

ball += i;

the globals for ball=400 and i=0

[/font][/font]

##### Share on other sites
So, do you have a question?

L. Spiro

##### Share on other sites
yes how do I move a ball around a screen.I am usign a 800 by 600 screen. and a 20 x 20 ball ..let me know if you need more info.

##### Share on other sites
FLOAT xVel = 1.0f; FLOAT yVel = 1.0f; FLOAT posX = 400.0f; FLOAT posY = 300.0f;

posX += xVel; posY += yVel; if ( posX <= 0.0f + 10.0f ) { posX = 0.0f + 10.0f; xVel = 1.0f; } else if ( posX >= 800.0f - 10.0f ) { posX = 800.0f - 10.0f; xVel = -1.0f; } if ( posY <= 0.0f + 10.0f ) { posY = 0.0f + 10.0f; yVel = 1.0f; } else if ( posY >= 600.0f - 10.0f ) { posY = 600.0f - 10.0f; yVel = -1.0f; }

L. Spiro

##### Share on other sites
thanks yogurt for all the help.I will try your code.

##### Share on other sites
cool your code works thanks.I have one more little question.I want to move my paddle left and right using the arrow keys, but I am confused about how to use vectrors to manipulate my paddle.here is some of my code.
[font="Consolas"][font="Consolas"]D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320,560,0);

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]for[/font][/font][/font][font="Consolas"][font="Consolas"]([/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]float[/font][/font][/font][font="Consolas"][font="Consolas"] i=0; i<=640; i+=160)

{

D3DXVECTOR3 vecPos_brickone = D3DXVECTOR3(i,120,0);

D3DXVECTOR3 vecPos_bricktwo = D3DXVECTOR3(i,160,0);

D3DXVECTOR3 vecPos_brickthree = D3DXVECTOR3(i,200,0);

[/font][/font][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"][font="Consolas"][color="#0000ff"]if[/font][/font][/font][font="Consolas"][font="Consolas"] (g_pD3DXSprite && g_pTexture)

{

g_pD3DXSprite->Begin( D3DXSPRITE_ALPHABLEND );

g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_upper, 0xffffffff);

g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);

g_pD3DXSprite->Draw(g_pTexture_two, NULL, NULL, &vecPos_brickone, 0xffffffff);

g_pD3DXSprite->Draw(g_pTexture_three, NULL, NULL, &vecPos_bricktwo, 0xffffffff);

g_pD3DXSprite->Draw(g_pTexture_four, NULL, NULL, &vecPos_brickthree, 0xffffffff);

g_pD3DXSprite->Draw(g_pTexture_ball, NULL, NULL, &vecPos_ball, 0xffffffff);

g_pD3DXSprite->End();

}

}

}

g_pD3DDevice->EndScene();

[/font][/font][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"][font="Consolas"][color="#008000"]// Frame buffer to Front buffer

[/font][/font][/font][font="Consolas"][font="Consolas"]g_pD3DDevice->Present( NULL, NULL, NULL, NULL );

}

{

D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320+m,560,0);

g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);

m--;

}

{

D3DXVECTOR3 vecPos_lower = D3DXVECTOR3(320+n,560,0);

g_pD3DXSprite->Draw(g_pTexture, NULL, NULL, &vecPos_lower, 0xffffffff);

n++;

}

the lower vector is the paddle I want to move.

[/font][/font]

##### Share on other sites
Paddle_Left() and Paddle_Right() are functions for moving the paddle, not rendering them. They need to be rendered every frame, not just when they are moving.

If they are meant to control the same paddle they should be using the same variable for the offset. Either m or n.

L. Spiro

##### Share on other sites
can you go into detail a little bit.

##### Share on other sites

can you go into detail a little bit.

Those two functions only change values associated with the paddle's position. They do not render it.

Rendering the paddle, however, needs to use that position in order to draw it in the right place on the screen each frame.

You should never mix input and draw code.

##### Share on other sites

Paddle_Left() and Paddle_Right() are functions for moving the paddle, not rendering them. They need to be rendered every frame, not just when they are moving.

If they are meant to control the same paddle they should be using the same variable for the offset. Either m or n.

L. Spiro

well I tried a few things but am still confused.

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5
khawk
11

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633677
• Total Posts
3013282
×