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 / Mouse hit and Sprite angle

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 26th Jan 2014 21:56 Edited at: 26th Jan 2014 22:00
Hi.

I have a code that when click to screen get Pointer Y coordinate and according Y coordinate, sprite angle is change. but I want when Mouse hit on the sprite and GetPointerstate() = 1 change the sprite angle.
I used below code for this work but I think is not correct, because my sprite angle is between 300-45 degree and when i try change the sprite angle with mouse, before come to 300 degree mousehit = 0.
also I want before click on the sprite and move mouse, sprite angle don't change. because when i click on the sprite change the angle before mouse movement.

Please Guide Me.

Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 26th Jan 2014 22:58 Edited at: 26th Jan 2014 23:04
Let me just check your working;
Quote: "(ScreenToWorldY(PointerY#) / GetVirtualHeight()"

(You actually don't need the ScreenToWorldY() part because pointerY() is a screen position and that is what you want to divide by the screen height)

- This returns a value between 0.0 (top of screen) and 1.0 (bottom of screen)
- multiply by 105 to get the range 0 (top) to 105 (bottom).
- add 300 to get the range 300 (top) and 405 (which equals 45) (bottom)

This looks correct if you want the angle to be set based on the absolute Y position of the mouse on screen. But since you asked the question, you want something else.

If you want to be able to click and drag, and the mouse angle moves from there, you need to store the Y position when the button was pressed and change the angle based on the difference.

something like this;

moveY can be both positive (mouse moved down) or negative (mouse moved up), this is ok, and should be scaled and added to the current sprite angle.

I have not included code to convert this, you clearly know the maths and the amount of rotation will take some trial and error to get right.

You could start with;

and go from there
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 27th Jan 2014 19:52
Quote: "
But since you asked the question, you want something else.
"


I want change the cannon angle with MouseY between (300-405) for fire ball. but there is two problem that I say in first post.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 28th Jan 2014 12:54
not sure if this help but maybe it is what you are looking for.


AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 28th Jan 2014 16:23
I was thinking along the lines;
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 28th Jan 2014 20:16 Edited at: 28th Jan 2014 20:31
Thanks Marl, Itself.
can you explanation about this line?



AGK Need Math knowledge but I don't know for write a code like your code, what is need in math. Because for several years I have not read the math.and think for this reason, I can't good write script in AGK.


Thanks Markus for your help.
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 28th Jan 2014 22:49
Quote: "can you explanation about this line?"

Sure.

You want angles in the range 300 to 45, but you want to go from 300 upwards and wrap around to 45.

This creates a problem because 45 is smaller than 300 so when the value wraps around from 359 to 0, the check for < 300 will show as true, even though the angle is OK.

To avoid this, we make sure that any angles less than 180 are adjusted to be bigger than 300, by adding a whole turn of 360 degrees.

This is why the second check is > 405 and not > 45.

This works because a sprite at 45 degrees is exactly the same as one at 405 degrees.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 29th Jan 2014 22:31
Thanks Marl for help and good explanation
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 30th Jan 2014 12:41 Edited at: 9th Feb 2014 17:39
I want control cannon angle with controller between max top and bottom of line-control sprite. can anyone help me?
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 4th Feb 2014 10:45
I made controller and can change the ngle but need guide for control angle between max and min seek.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 4th Feb 2014 15:54
Use an IF statement to control the range

Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 20th Feb 2014 10:52
why downY# = -1?
Marl
13
Years of Service
User Offline
Joined: 19th Nov 2011
Location: Bradford, UK
Posted: 21st Feb 2014 15:53
... like a bolt from the blue
Quote: "why downY# = -1?"

(short version)
Because downY# is the Y position of the pointer when the screen was touched and -1 is a place it is impossible to touch on the screen.
(longer version)
When the pointer is pressed, if a valid sprite was touched, it records the Y position, otherwise we use -1 to indicate that no sprite was touched. It's like a message to the next bit...

if getPointerState() and downY# > -1 only continues if;
1) the pointer is still touching the screen (getPointerState())
AND
2) a valid sprite was touched when the pointer was first pressed ( downY# > -1).

Both these conditions need to be true if we are going to change the angle.
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 21st Feb 2014 20:26
Thanks Marl.

Login to post a reply

Server time is: 2024-11-25 02:37:35
Your offset time is: 2024-11-25 02:37:35