Prevent random clicks
matrafonas

Hi,

In a HOG, how can i prevent the user to randomly click in the game area?

thank you

All 5 Comments
Gio

Hi

What do you want to happen when a random click occurs?

If you want to do something when the user clicks on the background, you can edit hiddenObject.js  and at the very end of the onMouseDown function (before line 29) add

return true;

Then select your background object, go to its Functions tab and select onMouseDown. In there you can define what you want to happen. For example lose some points or display a message.

matrafonas

hi,

Thank you for your reply,i undestand what you said,

Imagine if the player is "abusing" on random clicks, let's say 5 quick random clicks without finding an object, then display a message.

 

Gio

I see what you mean. You could add this code in the onMouseDown function of the background object (adjust the value of numClicks and time to define the maximum amount of clicks you want in the given time)

var numClicks = 5;
var time = 2;
wade.app.clickTime = wade.app.clickTime || [];
var now = wade.getAppTime();
wade.app.clickTime.push(now);
if (wade.app.clickTime.length >= numClicks && now - wade.app.clickTime[wade.app.clickTime.length-numClicks] < time)
{
	alert('Some message');
}

While this may work, in practice you'll want to do something better than just use alert. Perhaps create a SceneObject with a nicely formatted message, make it initially invisible and then show it when appropriate.

matrafonas

Hi 

thank's agian for you quick reply,

I think i might have a little problem, it works fine on a single test scene, but when i tried to implement in a game with more than one scene that i have it simply does not work, i put the return true; in hiddenObject.js but the background object doesnt even listen to OnMouseDown (i've put a console.log to see what happens here, and nothing) in these scene i also have a countdown timer, so when the the time reaches 0 the player loose one life.

Any idea of what might be happening?

thank you

matrafonas

Hi again

I should have noticed that Auto Listen was turned off :( now it's working just fine

Thank's again

Great support

Post a reply
Add Attachment
Submit Reply
Login to Reply