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

Recommended Posts

im tring to make a simple, game that bats a ball . . you know the type im sure ive drawn my paddle and am trying to make it move and used this code . .
void cPaddle::Draw()
{
D3DXVECTOR2 vTrans;
D3DXVECTOR2 vScale;

vTrans.x = 0.0f + ( GetXPos() );
vTrans.y = 0.0f + ( GetYPos() );

vScale.x = 0.5f;
vScale.y = 1.0f;

NULL, &vTrans, D3DCOLOR_RGBA(255,255,255,255));
}

{
if(KEYDOWN(VK_DELETE))
{
float a = GetXPos();
a += 0.05f;
}
}


how would i get this drawn image to move? im sure my move doesnt work as it doesnt know what its moving???

Share on other sites
Your not storing a in anything, so the increment is lost.

what you need is an x variable stored in the CPaddle class and the increment that...

{
if(KEYDOWN(VK_DELETE))
{
this->x += 0.05f;
}
}

Share on other sites
EDIT: And AGAIN I seem to be just that bit too slow today... [rolleyes]

Seems to me like a fairly simple syntax/semantics error in your code [oh]

if(KEYDOWN(VK_DELETE))	{		float a = GetXPos();		a += 0.05f;	}

Unless 'a' were a pointer of some kind, that operation will not actually alter the X position at all... the new/temporary value of 'a' will be discarded at the scope {}...

Maybe you need a SetXPos() function?

if(KEYDOWN(VK_DELETE))	{		SetXPos( GetXPos() + 0.05f );	}

hth
JAck

Share on other sites
How are you storing your coordinates? (The ones you get with GetXPos() and GetYPos() )

{
XPos -= 0.05f;
}

{
XPos += 0.05f;
}

then in your game loop do something like this:

if(KEYDOWN(left_key_code_here))
{
}

and so on...

edit: WAY too slow, man sorry...

Share on other sites
thank you people very very good

Share on other sites

if i create an image of .png and i want all of the white in the image to be transparent . . .how do i do this?

thanks people

Share on other sites
Use the png's alpha channel. "Erase" the white so it becomes transparent (after enabling the alpha channel).

Share on other sites
can u not do what i said thois . .specify a colour to alpha? . .if so say i loaded a png, what would the alpha specific code look like?

Share on other sites
ok so most of this is sorted but now i need pong ball code, i dont want crazy crap just rebounds at 45 degress. is there anywhere i can browse good easy to read code for this?

Share on other sites
Ok, here's some pseudo code:

{
YVel *= -1;
}

It will reverse the ball's velocity so it goes upward. If you hit side walls, you do this:

XVel *= -1;

If you hit top side, you do this:

YVel *= -1;

Just set the ball velocity to 45 degree movement in beginning, and those will take care of your physics.

So, example, XVel = 5, YVel = -5 will cause the ball to go up and right at exactly 45 degrees.

Hope this helps

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

• 13
• 26
• 10
• 11
• 9
• Forum Statistics

• Total Topics
633725
• Total Posts
3013558
×