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.

DarkBASIC Discussion / DBC - mouseclick() nightmare.

Author
Message
Stupot
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: East Sussex
Posted: 21st Jul 2006 00:18
I wonder if anyone could help me.
I'm making a 2d game using a similar controlling style as games such as MYST, where you click the right of the screen to go right, left to left, forwards to go straight on etc, etc.

I've worked out how to do this, thankfully without having to ask too many questions. But now I've hit a stumbling block.
whenever i click on a clickable part, it performs the action twice, so that if i click left (for example), I turn left, then i turn left again so that i'm facing behind me... of course i only want it to move once.

This is because it keeps reading that your finger is on the button. It seems that you really have to tap it quickly if you want to only turn left once, but this is difficult, and not ideal gameplay.

I've tried slowing the SYNC RATE down but this still occurs unless I slow it down to 10 or less but that just makes the cursor really slow.

I also tried putting CLS at the beginning of every new screen so try to block this from happening but a) it still happened and b) it flashed black in between screens.

I'll leave my code here in the hope that someone might be able to help me figure out what to do about this.
This is the code for a short experimental version of the game set in my living room. If anyone can give me hints on how to condense it aswell, i would be grateful.

Thanks guys

-Stu
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 21st Jul 2006 00:46 Edited at: 21st Jul 2006 00:51
What you need to do is set a flag when the mouse clicks... Here's an example:



That way it only runs it once until you release the mouse button.

And you said you want to condense it? Looks like you're running the same code over and over again to check what side you're clicking on... Try this function:



This will return a number corresponding to the side they clicked. That way you can just check if side() = 1 or if side() = 2.

Hope I made sense.

Stupot
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: East Sussex
Posted: 21st Jul 2006 01:06
Izzy, yes that made sense, I shall go now and see what I can do with this delicious information. Thanks a lot
I'll post here when I'm happy and let you know how I got on.

-Stu
Uncle Sam
19
Years of Service
User Offline
Joined: 23rd Jul 2005
Location: West Coast, USA
Posted: 25th Jul 2006 04:26 Edited at: 25th Jul 2006 04:26
Izzy, this:



can be changed to this:



Other part not necessar,y and tis way will run faster.

Uncle Sam
Nvidia Geforce 7600 GS 256MB PCIEx, 2.66 GHZ Pentium 4 proccessor, 768MB RAM
Need particles? Click here!
Stupot
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: East Sussex
Posted: 27th Jul 2006 00:38 Edited at: 27th Jul 2006 00:40
IZZY,

I've tried using your method to make my code more efficient:



Ive also added IFs for top and bottom as well as left right and centre but I haven't deviated from your pattern but, when i run it i get an error message saying: PROGRAM HAS RUN INTO FUNCION DECLARATION

does this mean anything to you and have you got any idea what might be causing it?

cheers,

-Stu
Izzy545
21
Years of Service
User Offline
Joined: 18th Feb 2004
Location:
Posted: 27th Jul 2006 04:43
Hmm... Where did you put the function code? It should be outside your main game loop, I think it has to be below the main game loop.

Stupot
18
Years of Service
User Offline
Joined: 13th Jul 2006
Location: East Sussex
Posted: 27th Jul 2006 17:05
Ahh, yes. I had it above the main loop, i've relegated it to the bottom of the code and it works just fine.

incase you're interested, this is what my code looks like now


It's not all that much shorter in terms of line count, but it's a hell of a lot more readable and will save me hours worth of typing when I came to make the real game.
Thanks Izzy, I owe you one.

-Stu

Login to post a reply

Server time is: 2025-05-25 10:42:53
Your offset time is: 2025-05-25 10:42:53