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.

Newcomers DBPro Corner / Mouse click over a randomly placed image

Author
Message
dolorismachina
14
Years of Service
User Offline
Joined: 12th Mar 2010
Location:
Posted: 12th Mar 2010 17:04
Hello everyone.
First of all I'm sorry for any language mistakes as English isn't my first language.

I want to create a simple pop ballons game and I have this code for random placing of the ballons.



So the ballons would hopefully come up randomly all over the game area.

I need help with code for clicking on them.


This obviously checks the mouse position and state.
But how do i check whether the user clicked the image or not? I can't use this obviously as I don't know where it will be:

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 12th Mar 2010 19:10
There are a couple of ways.

The first is to use Point(Mx,My). If the background is black and Point returns a value other than 0 you have clicked on a balloon.

But that then raises the question 'which balloon'?

Using the positionX, positionY variables only allows one balloon. So, instead you would create an array to hold the X and Y position of each balloon's top left corner.

So... if a click returns a number > 0 then go check it's position with those stored in the array.

For info on arrays, see tutorial 1 here:

http://forum.thegamecreators.com/?m=forum_view&t=99497&b=10

Alternatively, if you make each balloon a sprite you can attach a 1x1 pixel sprite to the mouse and test for collision when the mouse button is clicked. The advantage of this is that the collision command actually returns the number of the balloon sprite that was clicked on, so you don't even have to know where it is on the screen.

TDK

dolorismachina
14
Years of Service
User Offline
Joined: 12th Mar 2010
Location:
Posted: 12th Mar 2010 21:07
Thanks for the reply.
The second method seems quite good but if you could somehow guide me. I am not very good at programming. I'm not asking for the complete solution but just some tips on how to get it done.

Login to post a reply

Server time is: 2024-09-28 16:35:57
Your offset time is: 2024-09-28 16:35:57