Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / rotate sprite to mouse

Author
Message
seppeEnZigie
12
Years of Service
User Offline
Joined: 9th Apr 2012
Location:
Posted: 10th Apr 2012 21:46
hi,
im making a 2d shooter game and I need to rotate my sprite so it always looks at my cursor, I knwo that there are other posts about this and I looked at them bud i can\'t figure it out
here is my code:

POINT coord;
GetCursorPos(&coord);
#define PI 3.14159265
float dx = coord.x - dbSpriteX(1);
float dy = coord.y - dbSpriteY(1);
float rad = atan2(dy, dx);
float angle = rad * 180 / PI;
dbRotateSprite(1,angle);
I hope someone can help me

hello my name is zigie
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 11th Apr 2012 10:13
Code looks ok at a glance. Try using dbATanFull() assuming it exists (not used it yet in GDK). Assuming your problem is the sprite doesn't appear to point correctly all the time, it could be atan2 doesn't provide the extra range atanfull does. I believe it does something with wrapping/inverting/tweaking values to give you the correct angle for any orientation. Not tried this myself yet though.

seppeEnZigie
12
Years of Service
User Offline
Joined: 9th Apr 2012
Location:
Posted: 11th Apr 2012 14:21
Quote: "Code looks ok at a glance. Try using dbATanFull() assuming it exists (not used it yet in GDK). Assuming your problem is the sprite... "


i tried it but I can't get it to work my sprite rotates all weird.
I probably made ​​a stupid mistake

hello my name is zigie
seppeEnZigie
12
Years of Service
User Offline
Joined: 9th Apr 2012
Location:
Posted: 11th Apr 2012 14:33
oh I got it to work here is the code I changed coord.x and coord.y to dbMouseX() and dbMouseY

thanks evreyone for the suport

hello my name is zigie
Fallout
22
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 11th Apr 2012 17:52
I wondered where that GetCursorPos command was coming from. Glad you got it working.

Login to post a reply

Server time is: 2024-11-19 02:25:39
Your offset time is: 2024-11-19 02:25:39