|
Post by johnno56 on Mar 15, 2022 13:46:50 GMT -6
Working on the Scheme Editor, trying to control via the mouse, I tinkered together a simple mouse zone function (well... simple for me... lol) in this case, mouse hover and mouse click. I find it useful... Perhaps someone else can as well...
xmax = 640 ymax = 480 title$ = "button" center_x = windowpos_centered center_y = windowpos_centered WindowOpen(1,title$,center_x,center_y,xmax,ymax,WindowMode(1,0,0,0,0),1) SetWindowAutoClose(1, 0) CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0) ClearCanvas
Dim mx Dim my Dim mb
grey = rgb(170, 170, 170) white = rgb(255, 255, 255)
btn_x = 120 btn_y = 200 btn_w = 250 btn_h = 50
Function zone(xpos, ypos, width, height) ' Is the mouse within the button area? if mx > xpos and mx < xpos + width and my > ypos and my < ypos + height then return true else return false end if End Function
do clearCanvas mx = mousex my = mousey mb = mouseButton(0) setColor(grey): Rect(btn_x, btn_y, btn_w, btn_h)
if zone(btn_x, btn_y, btn_w, btn_h) then ' Hovering setColor(grey): RectFill(btn_x, btn_y, btn_w, btn_h) ' Click if mb = 1 then setColor(white): RectFill(btn_x, btn_y, btn_w, btn_h) end if end if
if Not WindowExists(1) Or WindowEvent_Close(1) Then end end if update() loop until key(27) = 1
|
|
|
Post by rosy on Mar 16, 2022 4:04:49 GMT -6
|
|
|
Post by johnno56 on Mar 16, 2022 6:19:11 GMT -6
Yes. It is a simple collision test... I used the word 'simple'. Because simple is what I like. You are correct. I do indeed love a lot of variables. Ah. You just gotta love those variables... lol SDLBasic uses 'HitBob() ans HitSprite() for collisions... RC, not so much. So I just modify different collision algorithms as I need them... 'mx' and 'my' are used because they are quicker to type than 'mousex' and 'mousey'... Like I said, I try to keep it simple... lol
|
|