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.

AppGameKit Classic Chat / Sprite rotation messed up

Author
Message
The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 14th Jan 2012 11:38
Hi, I just managed to track down a bug in my game that has been here since the beginning. The bug was that no matter If I called the SetDisplayAspect or not the display aspect would allways be 4:3. Turns out I had forgot to remove the command that is generated with the project

But now that I finaly managed to fix the bug, a new issue came up. The whole time I have been using Sin() cos() and Tan() to calculate the rotation of most of my sprites. But for some reason the rotation gets offset now. My gunshots for example seem to drift as all my other sprites. Is this intended or is it a bug. Im using display aspect 16:9 now if it matters...
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 14th Jan 2012 12:16
Do you use the SetSpriteOffset() command? This command determines the point at which the specified sprite rotates around.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jan 2012 12:45 Edited at: 14th Jan 2012 12:49
When using sin cos and tan you need to multiply the Y component by the aspect ratio so:
dx# = x2# - x1#
dy# = (y2# - y1#) * getDisplayAspect()

... for example.

This tripped me up a lot at first

Edit: make sure you use floats when setting it I.E. setDisplayAspect(4.0 / 3.0)

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jan 2012 13:23
That's useful to know, I've been using it to calculate position based on the accelerometer.

One thing I found odd with trig in AppGameKit and really confuses my program. Every now and then I get a result of 1.#J I have no idea what that means, maybe it was related to /0 or something similar.

The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 14th Jan 2012 13:23
Thanks for the reply, I will try that
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jan 2012 15:59
I haven't noticed that Batvink, does it cause a crash or did you just notice when printing the value? Could be it's a conversion to string that's causing it?

The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 14th Jan 2012 16:20
It worked in some cases but there are still to points where it's buged

2 of my fuctions.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 14th Jan 2012 16:57 Edited at: 14th Jan 2012 16:59

Try that, it should work. I normally set a constant to the value of the display aspect so I don't have to keep calling the command.

Edit: messed the first one up a bit sorry...

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 14th Jan 2012 17:14
Quote: "does it cause a crash or did you just notice when printing the value? Could be it's a conversion to string that's causing it?"


I know it's not working, because my sprite gets positioned incorrectly. The 1.#J must be a string representation of some obscure value.

I have found a reference to it in Crystal Reports/Excel and it doesn't involve /0, so I'm stumped.

The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 15th Jan 2012 00:19
Quote: "Try that, it should work. I normally set a constant to the value of the display aspect so I don't have to keep calling the command."


I allready tried that but it didn't work The sprites start at a weird angle but then they turn towards the target...
Hodgey
14
Years of Service
User Offline
Joined: 10th Oct 2009
Location: Australia
Posted: 15th Jan 2012 00:21
I managed to produce a -1.#IND00 with this:



I also found this.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 15th Jan 2012 10:29
I'll do some tests later and try to figure out your problem. Not on my computer at the moment.

baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 16th Jan 2012 10:18
Yes, the second function was wrong sorry, the Y component needed to be divided by the aspect ratio. Sorry!


The Zoq2
14
Years of Service
User Offline
Joined: 4th Nov 2009
Location: Linköping, Sweden
Posted: 16th Jan 2012 12:05 Edited at: 16th Jan 2012 14:34
Awsome, I will try it when I get home

Thanks for the help!

Edit Awsome it works

Login to post a reply

Server time is: 2024-04-25 18:22:14
Your offset time is: 2024-04-25 18:22:14