directx c++ moving a rect on the y axis...
how would I move a rectangle I have on the screen using the up and the down key. I get errors on this part of my code:
if(KEY_DOWN(VK_UP))
{
rect.y -= 5;
}
if(KEY_DOWN(VK_DOWN))
{
rect.y += 5;
}
it says:
D:\C++\tricks gurus\pong\pong beginnings.cpp(42) : warning C4101: ''buffer'' : unreferenced local variable
D:\C++\tricks gurus\pong\pong beginnings.cpp(162) : error C2065: ''KEY_DOWN'' : undeclared identifier
D:\C++\tricks gurus\pong\pong beginnings.cpp(164) : error C2039: ''y'' : is not a member of ''tagRECT''
d:\program files\microsoft visual studio\vc98\include\windef.h(287) : see declaration of ''tagRECT''
D:\C++\tricks gurus\pong\pong beginnings.cpp(168) : error C2039: ''y'' : is not a member of ''tagRECT''
d:\program files\microsoft visual studio\vc98\include\windef.h(287) : see declaration of ''tagRECT''
Error executing cl.exe.
does anyone have any advice.
I''m just trying to make a rectangle move up and down with keyboard input.
First, there is no x,y members in the RECT class. There is: top, bottom, left & right. Secondly, you have to define the KEY_DOWN macro (I prefer not to use the underscore), like so:
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
So your new code should look like:
Hope that helps
Will O''Connor, Flamma Productions.
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)
So your new code should look like:
#define KEY_DOWN(vk_code) ((GetAsyncKeyState(vk_code) & 0x8000) ? 1 : 0)// ...RECT rect;if(KEY_DOWN(VK_UP)) { rect.top -= 5; } if(KEY_DOWN(VK_DOWN)) { rect.top += 5; }
Hope that helps
Will O''Connor, Flamma Productions.
[email=webwill666@hotmail.com]Will O'Connor[/email], Flamma Productions.
If you want the RECT to remain the same height then you should also add or subtract from rect.bottom.
//Box moves down
rect.top += 5;
rect.bottom += 5;
//Box gets shorter
rect.top += 5;
Invader X
Invader''s Realm
//Box moves down
rect.top += 5;
rect.bottom += 5;
//Box gets shorter
rect.top += 5;
Invader X
Invader''s Realm
Ah, ok, I have never modified a RECT after initialization, so thanks for clearing that up .
Will O''Connor, Flamma Productions.
Will O''Connor, Flamma Productions.
[email=webwill666@hotmail.com]Will O'Connor[/email], Flamma Productions.
uhmm....
Don''t use RECT for starters.
That should hold the size values of your image.(height/width)
I would create a class/struct for the object you''re moving and
give it x&y values of the top-left position on the screen/map.
If you use the RECT like I mentioned, remember that the top &
left values are(if you''re not clipping them) 0 and the bottom
and right values are the height&width respectively. Not, as
one would assume, the last pixels on the edges.
-Hyatus
"da da da"
Don''t use RECT for starters.
That should hold the size values of your image.(height/width)
I would create a class/struct for the object you''re moving and
give it x&y values of the top-left position on the screen/map.
If you use the RECT like I mentioned, remember that the top &
left values are(if you''re not clipping them) 0 and the bottom
and right values are the height&width respectively. Not, as
one would assume, the last pixels on the edges.
-Hyatus
"da da da"
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement