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.

DarkBASIC Discussion / rotate sprite to mouse

Author
Message
seppeEnZigie
11
Years of Service
User Offline
Joined: 9th Apr 2012
Location:
Posted: 10th Apr 2012 14:08
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
BN2 Productions
20
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 10th Apr 2012 20:16
Hi seppeEnZigie,

Looking at your code, it looks like you are using DarkGDK. This forum is specifically for DarkBASIC classic, which, incidentally, doesn't support sprite rotation.

Here is the DarkGDK forum, I hope you get the help you need:

http://forum.thegamecreators.com/?m=forum_read&i=22

Great Quote:
"Time...LINE??? Time isn't made out of lines...it is made out of circles. That is why clocks are round!" -Caboose
seppeEnZigie
11
Years of Service
User Offline
Joined: 9th Apr 2012
Location:
Posted: 10th Apr 2012 21:45
okay thanks
i didn't now that

hello my name is zigie
Latch
17
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 10th Apr 2012 22:23
Quote: "...and I need to rotate my sprite so it always looks at my cursor"


Just in case anyone was interested in how to do it in DBC, I wrote an image rotate function I posted on code snippets some time ago. Though the function creates a bit of unnecessary overhead (it could definitely be improved), the idea is still sound:



Enjoy your day.

Login to post a reply

Server time is: 2024-03-29 05:21:18
Your offset time is: 2024-03-29 05:21:18