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 / collide Mouse and sprite

Author
Message
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Jan 2014 09:11 Edited at: 19th Jan 2014 09:21
Hi.
how can detect collide between mouse over or click on the sprite? there is function for this work?
sorry for more question, because I Only used GUI Engines and I am not familiar with Visual engines like AGK.

Thanks
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Jan 2014 10:22 Edited at: 19th Jan 2014 10:25
GetSpriteHit use the draw order, means you get the top sprite

spr=GetSpriteHit ( x, y )

1 or 0=GetSpriteHitTest ( iSpriteIndex, x, y )

sprites are in world coords!!
ScreenToWorldX ( x )
ScreenToWorldY ( y )

GetPointerPressed ()
GetPointerReleased ()
GetPointerState ()
GetPointerX ()
GetPointerY ()

alternate rectangle check
(mousex=>x1 and mousex<=x2) and (mousey=>y1 and mousey<=y2)

online docu with search/filter
http://www.appgamekit.com/documentation/search.html

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Jan 2014 12:58 Edited at: 19th Jan 2014 13:24
Thanks Markus. if possible Now I Need you Guide that how can Move sprite when GetPointerState () = 1? I only need guide and no any code. I want write my code with your help for better familiar with AppGameKit Functions.

This is my code Up to now:



Thanks
Kobaltic
12
Years of Service
User Offline
Joined: 24th Jan 2012
Location: PA, USA
Posted: 19th Jan 2014 13:36 Edited at: 19th Jan 2014 13:37
Behdadsoft, you should really check out the example games and example snippets that come with the engine. A lot of your questions are answered in those.

To answer your question, get the sprite's current location X and Y, and add or subtract a number (add to go one way subtract to go the other way). The bigger the number you use the faster your sprite will travel. Keep it in the main loop and start with 1 and go from there.

If you are doing move to where you touch the screen, then you also need to get the distance from where you click and where the sprite is.

If that is what you want, go to your AppGameKit install and go to here for an example with code.

AGK/IDE/Help/examples/sprites/8_move.htm

edit: typo fixed
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Jan 2014 17:05
previous code is according to Sprite Move Example at AGK. I've already seen it.

This is My code but don't move my sprite.

Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Jan 2014 18:41 Edited at: 19th Jan 2014 20:31
try this , and maybe use 3=kinematic at setspritePhysicson


AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Behdadsoft
15
Years of Service
User Offline
Joined: 7th Apr 2009
Location: Tehran-Iran
Posted: 19th Jan 2014 19:08
Thanks Markus,
I don't Think any example in AppGameKit could help me to write this code.

Your Calculation is according to Formula? really I love know how you can Calculation.
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 19th Jan 2014 20:26
at first i think about the steps i need,
then i write code for this steps.

at first the pointer is in screen coord, we need world coord for the sprite.
at click you want memory the sprite (because at mouse movement you get out of the sprite area)
at release forget the sprite handle.
at mouse down you want move the sprite.
then we need the delta from a to b for x and y axis.
the length i do not need but i left in code.
for movement i use 1/10 from the original difference because i did not want the movement in one step to the new mouse position.
then you set the new position.
ready
the click offset is special,based on experience,
if you not use this offset the sprite center want goto mouse pointer at click, means the sprite move without you move your mouse at click.
for calculation i think also step for step to get the result.

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670

Login to post a reply

Server time is: 2024-05-03 02:10:11
Your offset time is: 2024-05-03 02:10:11