Archived

This topic is now archived and is closed to further replies.

postulate

directx c++ moving a rect on the y axis...

Recommended Posts

postulate    122
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.

Share this post


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

  
#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.

Share this post


Link to post
Share on other sites
Hyatus    122
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"

Share this post


Link to post
Share on other sites