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 / Facing a point.

Author
Message
Kaichiro
14
Years of Service
User Offline
Joined: 19th Mar 2010
Location:
Posted: 19th Mar 2010 18:27
Hello,
I've been working on a 2D game from a programming class that uses the core ideas of an RTS in that you click on an object and then tell it where to move. The problem I'm having is that despite years of geometry and two math minors on the team with me, we just can't get the blasted thing to always look at the destination point. Below is the best working solution we've got which will have the critter looking the right way in only quadrants I and IV.
We've tried offsets, but they do little to help with quadrants II and III. Perhaps somebody has some working code to have the sprite always face a destination point and would like to post it?

(Bonus points if you rotate about the center (I'm using 64x64 bitmaps) instead of (0,0))

Thanks for any help in advance!
~Kai

--Warning: ugly amateur code ahead--

Hassan
15
Years of Service
User Offline
Joined: 4th May 2009
Location: <script> alert(1); </script>
Posted: 19th Mar 2010 19:41
so you want to point a sprite to some xy coords?


sorry for basic code, can be easily translated to C++, i found it after a quick search for "point sprite"

i think the c++ code should look like


Kaichiro
14
Years of Service
User Offline
Joined: 19th Mar 2010
Location:
Posted: 20th Mar 2010 22:46
Hmm, I used some similar code that didn't work earlier in development, but your code works like a charm. Thank you very much!
Kaichiro
14
Years of Service
User Offline
Joined: 19th Mar 2010
Location:
Posted: 20th Mar 2010 23:27
New issue.
I'm trying to have the sprite rotate about it's center, and I've got some code, but I simply can't please the compiler with it. Perhaps someone can give me a hand?



Gives me the error: "error C2106: '-=' : left operand must be l-value " for both operations.
I suspect it has something to do with position.X() being a const float* to the actual private value, _x (likewise for Y).
Defined here :


Does anyone have any insight into this?

thanks in advance,
~Kai
haliop
User Banned
Posted: 21st Mar 2010 16:41 Edited at: 21st Mar 2010 16:42
you can use dbOffsetSprite(ID,X,Y)

you should first place the new sprite at 0,0
then in the
dbOffsetSprite(ID,0+dbSpriteWidth(ID)/2,0+dbSpriteHeight(ID)/2);

this should do the trick

btw , remmber that 2D dosent support much for Floats
so if you have a sprite that is

lets say 51 width and 51 height /2
you will get 25.5 which will probably be rounded to 25 or 26 just keep that in mind
Kaichiro
14
Years of Service
User Offline
Joined: 19th Mar 2010
Location:
Posted: 21st Mar 2010 20:44
Ah yes, works great! Thank you!

However, if it's not too much to ask, can you still help me with the problem I was having, because it came up quite a bit, and I'd really like to be able to assign an X and Y value to my Sprites by the Vectors I created instead of just dbSprite(), and the only way I have in place is that Position.X() thing. Nevermind it never hurts to know an error...

Thanks again,
~Kai
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 21st Mar 2010 20:59 Edited at: 21st Mar 2010 21:00
Quote: ""error C2106: '-=' : left operand must be l-value ""


Your crit->position.X() and crit->position.Y() are functions, not variables. You cannot assign a value to a function, it doesn't make sense. Either make them public variables so that you can assign directly their values, or write setter functions which take the new value as a parameter and then set the private variable within the class.
Kaichiro
14
Years of Service
User Offline
Joined: 19th Mar 2010
Location:
Posted: 22nd Mar 2010 00:40
Hmm, that's a fair point. Not sure why that didn't occur to me earlier. Thank you all very much for the timely and accurate help!
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 22nd Mar 2010 03:53
You can assign to functions just fine, assuming you return a non-cost reference. You're returning a const pointer which for a vector makes no sense in the slightest, just return a value or reference.

Login to post a reply

Server time is: 2024-10-02 03:31:27
Your offset time is: 2024-10-02 03:31:27