Moving a Box with the Mouse
BlitzPlus Forums/BlitzPlus Beginners Area/Moving a Box with the Mouse
| ||
Ok, how would I make it so, where ever you click on the "Title" image, and left click is down. And you move your mouse and the box moves with it. So I'm thinking, you'd need to know your MouseX and MouseY, then make something analyse, if your mosue is on the image. Then check if your left click is down. Then compare your MouseX and MouseY with your box_x and box_y. So like if your mouse moves while doing the two things it notes a +number or -number and applies it to the box_x and box_y. Well thats just my theorie tho lol.. But how would i do that? Thanks for the help. Graphics 640,480,32,2 SetBuffer BackBuffer() ClsColor(190,190,190):Cls:Flip ; VARIABLES Global exitGame = False Global title = LoadImage("gfx/title.jpg") Global content = LoadImage("gfx/content.jpg") Global box_x, box_y Repeat ; START { Cls box_x=20 box_y=20 DrawImage title, box_x, box_y DrawImage content, box_x, box_y+18 Flip ; EXIT GAME If KeyDown(1) exitGame=True EndIf ; END } Until (exitGame = True) End ; FUNCTIONS Function saveGame() End Function |
| ||
hmm.. Blitz Community is dieing... Gah. |
| ||
Do you wonder why with an explanation like that? Start at the beginiing Kaisuo and explain things slowly and accurately. You never know, someone might actually understand what you are saying and MAYBE they will provide a solution - stranger things have happened! |
| ||
Perhaps this is of some help to you.Graphics 640,480,32,2 ; setup type to use for button control Type BOX Field X#, Y#, WIDTH, HEIGHT, IMAGE, DRAGGED End Type ; create an image to use as a button temp = CreateImage( 128, 64 ) SetBuffer ImageBuffer( temp ) Color 200,200,200 Rect 0,0,128,64 Color 255,255,255 Rect 0,0,128,4 Rect 0,0,4,60 Color 100,100,100 Rect 124,4,4,60 Rect 0,60,128,4 Color 10,10,10 Text 24,24,"TEST BUTTON" ; create 5 buttons For i = 0 To 4 box = newBox( Rnd( 100, 500 ), Rnd( 100, 400 ), temp ) Next SetBuffer BackBuffer() While Not KeyHit(1) Cls drawBoxes() updateBoxes() Flip Wend End Function newBox( X#, Y#, IMAGE ) b.box = New box b\x# = X# b\y# = Y# b\width = ImageWidth( IMAGE ) b\height = ImageHeight( IMAGE ) b\image = IMAGE b\dragged = False End Function Function updateBoxes() MD = MouseDown( 1 ) MH = MouseHit( 1 ) MX = MouseX() MY = MouseY() MXS = MouseXSpeed() MYS = MouseYSpeed() If MD Then For b.box = Each box If MH And MX => b\x# And MX < (b\x#+b\width) And MY => b\y# And MY < b\y#+b\height Then b\dragged = True If b\dragged Then b\x# = b\x# + MXS b\y# = b\y# + MYS End If Next Else For b.box = Each box b\dragged = False Next End If End Function Function drawBoxes() For b.box = Each box DrawBlock b\image, b\x#, b\y# Next End Function |
| ||
Copy, Pasted and tested that code. This is what I wanted somewhat. Could anyone explain abit this to me in detail. This gonna help my learning of Blitz Alot of symbol :| If MH And MX => b\x# And MX < (b\x#+b\width) And MY => b\y# And MY < b\y#+b\height Then b\dragged = True Function updateBoxes() MD = MouseDown( 1 ) MH = MouseHit( 1 ) MX = MouseX() MY = MouseY() MXS = MouseXSpeed() MYS = MouseYSpeed() If MD Then For b.box = Each box If MH And MX => b\x# And MX < (b\x#+b\width) And MY => b\y# And MY < b\y#+b\height Then b\dragged = True If b\dragged Then b\x# = b\x# + MXS b\y# = b\y# + MYS End If Next Else For b.box = Each box b\dragged = False Next End If End Function |
| ||
Ok guys I really cant seem to get the code working using my image and all o.o What I'm trying to do is mouse my title image around, like thoses buttons while the content image follows... The math is abit hard ._.; Any help would be greatfully appreciated! |