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 / How do you make it so you can click on a bitmap to start the game?

Author
Message
ADGamer
19
Years of Service
User Offline
Joined: 25th Sep 2004
Location:
Posted: 23rd Mar 2005 02:35 Edited at: 1st Jul 2009 08:56
1

Underworld 1020
20
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 23rd Mar 2005 08:08 Edited at: 23rd Mar 2005 08:10
You can use this simple function I made a while back, which is very useful.

Here it is:


You can actually put the if statement into a single line, but I usually don't.

So here's an example of how to use it:


You need to put five parammeters into the "ClickBox" function. The first two are you're button's top left positions (x,y). The third and fourth are the button's bottom right positions (x,y). And the last is what click value, a 0 means no click, a 1 means left click, a 2 means right click, and a 3 means a left and right click together.

The "ClickBox" function will return either a 0 for false or a 1 for true. And thats all there is to it, let me know if you have any questions .

ADGamer
19
Years of Service
User Offline
Joined: 25th Sep 2004
Location:
Posted: 23rd Mar 2005 10:27 Edited at: 1st Jul 2009 08:56
2

Kentaree
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 23rd Mar 2005 17:09
Mantis, make sure you have code other than just the function declaration in your file, or it'll encounter just the function when it tries to execute, and will bomb out.

Desktop: AMD Athlon XP2800+,Radeon 9800 128MB, 1GB DDR RAM
Laptop: AMD Athlon 64M 3000+,Mobility Radeon 9700 128MB, 512MB DDR RAM
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Mar 2005 17:23 Edited at: 23rd Mar 2005 17:23
Another way is to use sprite collision. Check the cursor sprite against the button sprite.

SPRITE COLLISION
This command will return a one if the specified sprite is overlapping the target sprite specified. If a target sprite has not been specified and a value of zero has been used, this command will return the sprite number of any sprite overlapping it. The parameters should be specified using integer values.

BatVink
Kentaree
21
Years of Service
User Offline
Joined: 5th Oct 2002
Location: Clonmel, Ireland
Posted: 23rd Mar 2005 17:26
@Batvink: That does work, and is nice and easy, but isn't that quite slow?

Desktop: AMD Athlon XP2800+,Radeon 9800 128MB, 1GB DDR RAM
Laptop: AMD Athlon 64M 3000+,Mobility Radeon 9700 128MB, 512MB DDR RAM
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 23rd Mar 2005 23:18 Edited at: 23rd Mar 2005 23:18
Well, I had a 2D game that involved clicking sprites. Originally, I used my own collision in exactly the same way Underworld describes. Then, I changed it to sprite collision, and I got exactly the same performance.

This was with ~ 20 sprites. For a menu, peformance is not a huge consideration anyway.

It would be good to know if anyone has some hard data on Sprite Collision and what to expect. My game didn't exactly push the boundaries with 20 sprites!

BatVink
Underworld 1020
20
Years of Service
User Offline
Joined: 2nd Mar 2004
Location: NY, USA
Posted: 23rd Mar 2005 23:45
In my gamr "Gems" the mouse is actually a sprite and also the gems are too. Then I just check for sprite collison, so I don't have to specify coordinates and also the buttons and stuff don't have to be square, they can be round or any shape for that matter. The only problem is when you start getting a lot of sprites with black in them, which turns transparent, your program will slow down. That's why all the gem sprites in my game are going to be cut down a little to make the game faster, were just going to take the black out.

But for the "ClickBox" function, the button will have to be square. Try the second example I posted, that code will execute. The reason why you're getting a "Ran Into Function Declartion" error is because you can't just execute a function, it has to be called.

That's what this line is for:


That line calls the "ClickBox" function and checks to see if it returns 0 or 1. If you want you can use the sprite collision method, and if you need help just ask .

ADGamer
19
Years of Service
User Offline
Joined: 25th Sep 2004
Location:
Posted: 24th Mar 2005 00:36 Edited at: 1st Jul 2009 08:56
3

Login to post a reply

Server time is: 2024-09-23 15:39:56
Your offset time is: 2024-09-23 15:39:56