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 / Detect an area of a sprite?

Author
Message
2D Analyst
AGK Developer
20
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 9th Apr 2016 19:49
I would like to use 1 sprite if possible. The sprite I have is a rectangle shape and the player needs to left tap and right tap, repeat, etc on this block to score block.

Is there a built in function that does this already? If not, I'm thinking of using a math formula to get the center of the rectangle and then check to see whether touch point is left or right of it.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 10th Apr 2016 10:17
u need
GetSpriteXByOffset ( iSpriteIndex )
GetSpriteYByOffset ( iSpriteIndex )
GetSpriteHit ( x, y )
GetSpriteHitCategory ( categories, x, y )
GetSpriteHitGroup ( group, x, y )
GetSpriteHitTest ( iSpriteIndex, x, y )

GetPointerPressed () or GetPointerReleased ()
GetPointerX ()
GetPointerY ()
u can make a function with parameter spriteindex and it returns 1-4 for the edges.
just call hit test 4 times and add/sub a value at the pointer
example.
d#=1.0
GetSpriteHitTest ( iSpriteIndex, x-d#, y-d# )
GetSpriteHitTest ( iSpriteIndex, x+d#, y-d# )
GetSpriteHitTest ( iSpriteIndex, x+d#, y+d# )
GetSpriteHitTest ( iSpriteIndex, x-d#, y+d# )
AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)
2D Analyst
AGK Developer
20
Years of Service
User Offline
Joined: 2nd May 2004
Location:
Posted: 12th Apr 2016 03:57
Thanks, this is exactly what I'm looking for!
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 12th Apr 2016 07:46
emmm, today i think hit test will always return 1 over your sprite.
after hit you can use a if then condition if the x is left or right from sprite center.
else maybe u can change the shape after hittest and make another hittest for left/right.
AGK (Steam) V2.0.18 : Windows 10 Pro 64 Bit : AMD (15.30.1025) Radeon R7 265 : Mac mini OS X 10.10 (Yosemite)

Login to post a reply

Server time is: 2024-11-17 07:03:54
Your offset time is: 2024-11-17 07:03:54