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 / click on sprite, mouse must be moved away, FAST

Author
Message
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 28th Sep 2013 17:23
I have some sprites on the screen that can be clicked to choose which multiplacation tables to use. When a sprite is clicked it changes colour from yellow to green. This works OK but, if I am a little slow in releasing the mouse then it changes back to yellow.

I am using
if GetPointerState()=1
id = GetSpriteHit(GetPointerX(),GetPointerY()) and have had to include a sleep(100) or a repeat until loop to slow things down but, there ust be a better way to do this. Any ideas?
mr_d
DBPro Tool Maker
17
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 28th Sep 2013 17:42
Hi Rob from Scotland,

I would suggest you implement a very simple state machine, such that when the sprite is clicked on the state is set say from 0 to 1, and when the mouse is released, depending on where the pointer was when this happened, the state can be moved to 2 (if still on the sprite) or back to 0 (if not on the sprite). this will mean that the sprite should stay green if the state is not 0. you shouldn't need to have any delay this way. hope that helps. cheers.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 28th Sep 2013 22:49
Mr_d's solution is the best way to achieve this. It allows you to do all sorts of other effects, like change the size/colour of buttons as a visual indication.

But if you just want a really quick solution for the time being then change:

if GetPointerState()=1

to

if GetPointerReleased()=1

This must be checked between every Sync(), as it is only set to 1 for a single cycle.

Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 28th Sep 2013 23:47
You need to use a flag.


But Batvink's method is better I think for your need.

Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 29th Sep 2013 11:51
My thanks to all three of you. I have used BatVink's really quick solution since I already had the colour change buttons going, but now they don't flick back to yellow.

I'll keep mr_d's solution in mind for future use though and Phaelax's implementation.

Thanks!
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Sep 2013 15:31 Edited at: 29th Sep 2013 15:31
It can get quite complicated. This is my full implementation of mouse click detection. It accounts for mouseOver, mouseClick, and moving between objects whilst the mouse is depressed - you could mouseDown on one object and mouseUp on another .



Attachments

Login to view attachments
Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 29th Sep 2013 18:00
BatVink, what tool are you using to create your state diagram?

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
Rob from Scotland
21
Years of Service
User Offline
Joined: 23rd Aug 2003
Location: Scotland
Posted: 29th Sep 2013 18:14
I had thought that my problem was solved and that I would have no need to write on this topic again but, I can't help but be impressed with BatVink's state siagram. It reminds me of why I should have gone with engineering years ago.
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Sep 2013 18:36 Edited at: 29th Sep 2013 18:37
I'm using FreePlane, a progression of the original Freemind.

There are more comprehensive tools out there, but this tool is furiously fast when you just want a simple diagram. Using <Enter> (Sibling), <Insert> (Child) and the arrow keys you can whip something up in no time.

When I'm done, I use the simple colouring tool to mark the nodes green as I have coded them.


Believe it or not, I coded the above routine first time with no errors by using the state diagram. (It was a unique achievement, but I'm proud of it nonetheless!)

Here is an other example in the interface where I am constructing my file relationships. There is no recognised methodology here except my own confused mind.



Attachments

Login to view attachments
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Sep 2013 18:55 Edited at: 29th Sep 2013 18:56
Apologies, I'm going to take this post off-topic and talk a bit more. These diagrams are just so valuable, I have to share a bit more.

I've always been one for Rapid Development (RAD) - throw some code in and see if it works, then throw the next bit in. I always code the less attractive stuff first, then bring it to life later. This method has numerous advantages but it can also lead to all sorts of problems because visually there is very little to see, and what you coded may not be what happens.

So...these diagrams add visualisation to code where there is nothing to see, and makes sure that you are a lot closer to what you envisaged.

Secondly, it's so much easier to track down flaws in your logic before you even start.

Thirdly, it makes you code in state machine format. I know not everybody likes it, but I recommend everyone in the procedural (basic) coding world gets to like it. It's the easiest way to move towards simulated event-driven programming (opens up a door for another off-topic conversation).

Fourthly, it's just a damn good way to get your ideas on virtual paper. I'm trying to create a gameplay state machine that can handle a sequence of screens. Some are quiz questions, some are intro screens, some are adverts and so on. This visual method is helping me to work out how I can use the same code to deliver questions, answers, ads and intros without differentiating between them.

I'll stop going on and on now!

Disclaimer: I do not use any regimental method and I am no expert on coding methodologies. I simply use what works for me.

Ancient Lady
Valued Member
20
Years of Service
User Offline
Joined: 17th Mar 2004
Location: Anchorage, Alaska, USA
Posted: 29th Sep 2013 19:09
BatVink, thank you very much. This is exactly the kind of tool I like to work with.

AGK Tier 2 by necessity needs to be done using state machines (because of how Sync() works differently between the Tiers). I have created a good tutorial on it, with complete code. But the length became a bit much for one 'page' and I have been slowly making it multiple linked pages.

It is a tool that might come in very handy for newer programmers as well because it will help them work out the process and properly visualize it without having the code done yet.

Thank you again.

Cheers,
Ancient Lady
AGK Community Tester and AppGameKit Master
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 29th Sep 2013 19:14
No problem. If you want to share your tutorial in the newsletter you are more than welcome to get in touch. People love tutorials.

george++
AGK Tool Maker
17
Years of Service
User Offline
Joined: 13th May 2007
Location: Thessaloniki, Hellas
Posted: 29th Sep 2013 19:38 Edited at: 29th Sep 2013 19:45
@Rob from Scotland: If I got the point then this could be a solution
JimHawkins
15
Years of Service
User Offline
Joined: 26th Jul 2009
Location: Hull - UK
Posted: 1st Oct 2013 17:08
I'm old-fashioned. I do with paper and pencil!

-- Jim - When is there going to be a release?
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 1st Oct 2013 17:34
also a good mindmap online tool
http://mindmapfree.com/

Login to post a reply

Server time is: 2024-11-24 19:44:44
Your offset time is: 2024-11-24 19:44:44