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 / pressing buttons!

Author
Message
kfoong
21
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 16th Feb 2003 03:54
Does anyone know how to make buttons for the mouse to press? or an object can be pressed by the mouse and something will happen?
--------
I HAVE SOME IDEA HOW TO PROGRAM DARK BASIC!
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 16th Feb 2003 04:47
it's not so hard to do a button, would be harder for a 3d object but here is the basic code
kfoong
21
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 16th Feb 2003 05:18
could you please not put it in the "code snippet" button because me netscape doesnt do anything and my internet explorer is refusing to work. put it in the post please

--------
I HAVE SOME IDEA HOW TO PROGRAM DARK BASIC!
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 16th Feb 2003 05:35
ok here it is again

DO
BOX 100,100,200,200
if mousex() > 100 and mousex() < 200 and mousey() > 100 and mousy < 200 and mouseclick() = 1
set cursor 125,150
PRINT "BUTTON"
endif

LOOP
kfoong
21
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 16th Feb 2003 05:53
but would it be useful if the box moved around?

--------
I HAVE SOME IDEA HOW TO PROGRAM DARK BASIC!
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 16th Feb 2003 05:58
Then, make the box a sprite, then find the location of the sprite, and the width of the bitmap used to make the sprite and use those coordinates

RPGamer

Current - RPG: Eternal Destiny
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 16th Feb 2003 10:47
I'm board so i'll do the code for RPGamer's post.
I'm using DBC so this might not work in Pro.

Create bitmap 1,100,100
box 1,1,99,99
get image 1,0,0,100,100
set cursor 20,20
print "BUTTON"
get image 2,0,0,100,100
delete bitmap 1
REM I find this helps the edges of the images I capture so REM they don't get cut-off

RANDOMIZE TIMER()
REM re-seeding RND function so it will change every time

SPRITE_X = RND(540)
SPRITE_Y = RND(380)
REM not quite using the whole screen so the while sprite will be visabel

SPRITE 1,SPRITE_X,SPRITE_Y,1


DO

IF MOUSEX() > SPRITE_X and MOUSEX() < SPRITE_X+100 AND MOUSEY() > SPRITE_Y and MOUSEY() < SPRITE_Y+100 AND MOUSECLICK() = 1 Then SPRITE 1,SPRITE_X,SPRITE_Y,2

CLS
wait 0050
SPRITE 1,SPRITE_X,SPRITE_Y,1

LOOP


That oughta do it, now you have a sprite that changes image numbers when clicked.
kfoong
21
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 16th Feb 2003 11:04
i need 3d button please if you can make it.

--------
I HAVE SOME IDEA HOW TO PROGRAM DARK BASIC!
Puffy
22
Years of Service
User Offline
Joined: 4th Sep 2002
Location: United States
Posted: 16th Feb 2003 12:52
O_O You mean a 3d object or do you want him to make a button for you...

AMD Athlon XP 2100+ OC to 3Ghz/1.5gigs ram/128mb ti4200/120gigs hd/19" monitor/Sound Blaster Audigy Platinum EX/3072kbs Sat Con... I joined in!
John H
Retired Moderator
22
Years of Service
User Offline
Joined: 14th Oct 2002
Location: Burlington, VT
Posted: 16th Feb 2003 15:37
He means clicking on a 3D button.

Thats a little different cuz the mouse doesnt check for Z distance.

RPGamer

Current - RPG: Eternal Destiny
http://www.halbrosproductions.netfirms.com
Dont ask those questions! Read the help files lazy!
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 16th Feb 2003 23:22
before I actually write more code, do you mean like a 3d-button that is like animated when clicked or just a button code that will react when you click on a 3d object?
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 17th Feb 2003 00:14
ok here is the code for clicking on a 3d object, however there is a problem with this, if you move the camera then the collision box won't be in the right place. So it wouldn't be very usefull if you plan on moving the camera which is why making a 3d button is kinda difficult. As a side note, does anyone know the math that would allow you to move the collision box with the camera and always keep it over the object. I'm sure it can be done but not by me.


gosub initial_variabels


make object plain 1,object_width,object_height
position object 1,object_x,object_y,object_z
position camera object_x,oject_y,object_z-50



do

if mousex() > collision_box_x and mousex() < collision_box_x2 and mousey() > collision_box_y1 and mousey() < collision_box_y2 and mouseclick() =1
color object 1,RGB(0,255,0)
endif
print mousex()
print mousey()
set cursor 0,0
color object 1,RGB(255,0,0)
loop





initial_variabels:
object_x = 0
object_y = 0
object_z = 0
object_width = 10
object_height = 10
collision_box_x1 = 275
collision_box_y1 = 95
collision_box_x2 = 360
collision_box_y2 = 180
return

`another problem is that the collision box isn't accurate to the objects position (i.e. because the object is 3d it ain't exactly square with the camera so the box would require many more variabels to fit exactly around the object)
Omikronian
21
Years of Service
User Offline
Joined: 15th Dec 2002
Location:
Posted: 17th Feb 2003 01:19
kfoong come on over to my webpage and download my menu demo. It will show you how to create 2d buttons that when clicked on can do whatever you want them to. Full source included!
http://members.aol.com/alp29b/default.htm

OneTouch
21
Years of Service
User Offline
Joined: 23rd Jan 2003
Location:
Posted: 17th Feb 2003 19:45
Omikronian:
Your stuff is awsome.
I hope you don't mind but I just linked to you
on my webpage.

Thanks for the inderict help.

need more information on game development,
visit http://www.dtagames.com
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 18th Feb 2003 23:13
as long as you make it so the button dosen't move around you can use the exact same code I posted earlier. essentialy your making a 2d button on the screen that just happens to be where a 3d graphic of a button is.
kfoong
21
Years of Service
User Offline
Joined: 28th Jan 2003
Location: Australia
Posted: 19th Feb 2003 11:04
Jadelion, very good! but why doesnt it work when i put on the sync to make it look better?

Omikronian, Sorry i dont have DBP

Chronic Programmer, I think i said earlier that i couldnt view code snippets...

--------
I HAVE SOME IDEA HOW TO PROGRAM DARK BASIC!
Shadow
22
Years of Service
User Offline
Joined: 17th Oct 2002
Location: In the shadows
Posted: 19th Feb 2003 21:06
My button function:

In main loop write-
if clickbutton(100,100,200,"Hello") then text 1,1,"text"


function clickbutton(x0,y0,x1,st$)
y1=y0+20
ink 0,0: box x0,y0,x1,y1
ink rgb(192,192,192),0: box x0+1,y0+1,x1-1,y1-1
ink 0,0: center text (x0+x1)/2,y0+2,st$

moX=mousex():moY=mousey()
if moX>x0 and moX<x1 and moY>y0 and moY<y1 and mouseclick()=1 then click=1: bclick(0)=1 else click=0

ink rgb(255,255,255),0
endfunction click
BackBONE
21
Years of Service
User Offline
Joined: 18th Feb 2003
Location:
Posted: 19th Feb 2003 21:21
in case of sprites as button`s its much easer to use a simple sprite (2*2Pixels) and position it at the mousepointer. Then U can use Spritecollision comands!

To lazy to put some Code know
Jadelion
21
Years of Service
User Offline
Joined: 14th Jan 2003
Location:
Posted: 20th Feb 2003 01:44
alright, I added the sync command and you are right, it did stop working, but I think this is because the added refresh is making the color change un-noticabel. So I added a wait command after then button is clicked and now it works again and the box actually stays green for awhile.

gosub initial_variabels


make object plain 1,object_width,object_height
position object 1,object_x,object_y,object_z
position camera object_x,oject_y,object_z-50

sync on

do
sync
if mousex() > collision_box_x and mousex() < collision_box_x2 and mousey() > collision_box_y1 and mousey() < collision_box_y2 and mouseclick() =1
color object 1,RGB(0,255,0)
wait 1000
endif
print mousex()
print mousey()
set cursor 0,0
color object 1,RGB(255,0,0)
loop





initial_variabels:
object_x = 0
object_y = 0
object_z = 0
object_width = 10
object_height = 10
collision_box_x1 = 275
collision_box_y1 = 95
collision_box_x2 = 360
collision_box_y2 = 180
return
xmen
21
Years of Service
User Offline
Joined: 27th Jan 2003
Location:
Posted: 20th Feb 2003 01:56
Try this hope it help

Login to post a reply

Server time is: 2024-11-24 03:50:47
Your offset time is: 2024-11-24 03:50:47