2d stuff
Blitz3D Forums/Blitz3D Beginners Area/2d stuff
| ||
Hi i am making a 2d thing and i'm trying to get it so when i click on one image another will apear till i click on it again or if i click off it but i dont know how plese help me. please reply soon |
| ||
First of all, please write with good grammer so that people can understand you. Check out the documentation, and look at things like RectsOverlap() or ImagesOverlap(). These are probably the commands you will need. |
| ||
i use those commands, what i have got is basically when i click a image another one appears but if i let go of the mouse button it goes, and if i use the mousehit command it still dont work i need it so that the image stay displayed on screen till i click it again or click off of it. |
| ||
It sounds like you are just doing DrawImage when the mouse button is down. What you need to do is set a variable to hold the state of the mousebutton. If that's set, draw the image. When you click the button you can check the status of that variable, if it's set, or unset, change it to the opposite. If that's not it, you'll need to post some source code. |
| ||
Goober @ Yeh if you don't whatch your grammer you'll turn intp me |
| ||
@Rich05 , may not be language may not be his first, english, and his english gram'mar maybe poor :) |
| ||
Ok here is my source code: Graphics 1024,740,32,2 SetBuffer BackBuffer() HidePointer button=LoadImage("Button.bmp") popup=LoadImage("popup.bmp") pointer=LoadImage("Mouse pointer.bmp") While Not KeyHit(1) Flip Cls Color 0,0,0 DrawImage button,0,711 If ImagesOverlap (pointer,MouseX(),MouseY(),button,0,711) And MouseDown(1) Then DrawImage popup,0,417 EndIf DrawImage pointer,MouseX(),MouseY() Wend End I'm just not sure how to get it to stay down like doing a state sort of thing, please help. also sorry if my english seems bad i'm 14 and i aint that good at english, lol. |
| ||
1) put the Flip command just after the latest Drawimage, and before the Wend statement 2) choose a standard screen resolution. More, if you want that your game ran on other pcs, choose a smaller resolution: Graphics 640,480,0,1 ;(2 for windowed) or Graphics 800,600,0,1 ;(2 for windowed) should be fine. 3) I would change the If statement, checking first the mousedown(), because it happens less frequently, so it would make the process slight faster: If Mousedown(1) then If ImagesOverlap (pointer,MouseX(),MouseY(),button,0,711) then . . 4) do not use fixed numbers to indicate where to display your image. If you write in your code 100 times: drawimage popup,700,14 and then you want to change the coordinates, you have to edit it 100 times. Instead, declare two variables like, for example, buttonx and buttony, and use them when you draw the image on the screen: drawimage button,buttonx,buttony About the status thingy. Basically, you may do in this way: if the left button mouse has been pressed then if it has been pressed on an image then change status to the image flag endif endif And, in the main loop: if the image status is 1 then display it . . flip wend The image status does not exist really, but you can create a flag (or use a type structure, but perhaps right now is too complicated if you are a beginner). So, for example: my_img = LoadImage("popup.png") my_img_status = 0 my_imgx = 100 my_imgy = 100 . . if mousehit(1) then ;left mouse click ? flushmouse() ;reset mouse if imagesoverlap(mouse_img,mousex(),mousey(),button,buttonx,buttony) then my_img_status = 1 - my_img_status ;this will toggle between 0 and 1 endif endif ; ; if my_img_status = 1 then drawimage my_img,my_imgx,my_imgy endif flip wend In the example above, the image my_img will be displayed when you left click on it, and will disappear if you left click again on it. Hope this has sense for you, Sergio. |
| ||
it's not working i got it so it stays up but i cant get it to go away again here is my updated code: Graphics 1024,740,32,2 SetBuffer BackBuffer() HidePointer button=LoadImage("Button.bmp") popup=LoadImage("popup.bmp") popupstat=0 pointer=LoadImage("Mouse pointer.bmp") While Not KeyHit(1) Flip Cls Color 0,0,0 DrawImage button,0,711 If MouseHit(1) Then If ImagesOverlap (pointer,MouseX(),MouseY(),button,0,711) popupstat=1 EndIf EndIf If popupstat=1 Then DrawImage popup,0,417 EndIf If popupstat=1 Then If MouseHit(1) Then If ImagesOverlap (pointer,MouseX(),MouseY(),button,0,711)=0 Then popupstat=0 EndIf EndIf EndIf DrawImage pointer,MouseX(),MouseY() Wend End what is wrong with it now. |
| ||
Well, as far as i know, if you check for a mouse hit(), any further references to mousehit() will return false.if mousehit(1) then ;left mouse click ? flushmouse() ;reset mouse if imagesoverlap(mouse_img,mousex(),mousey(),button,buttonx,buttony) then my_img_status = 1 - my_img_status ;this will toggle between 0 and 1 endif endif You should have kept the code the same as semar done it. It will work that way :) |
| ||
can you please give a working example for me please cause bits of coding dont really help me much cause i get all comfused in all kinda ways, please please pelase working code please please please |
| ||
please help me i need your knowledge. |
| ||
USE SEMARS CODE! how hard is that? [CODE]Graphics 1024,768,32,2 SetBuffer BackBuffer() HidePointer button = LoadImage("Button.bmp") buttonx = 0 buttony = 711 my_img = LoadImage("popup.png") my_img_status = 0 my_imgx = 100 my_imgy = 100 pointer = LoadImage("Mouse pointer.bmp") While Not KeyHit(1) mx = mousex() my = mousey() Cls DrawImage button, buttonx, buttony if mousehit(1) then ;left mouse click ? flushmouse() ;reset mouse if imagesoverlap(pointer,mx,my,button,buttonx,buttony) then my_img_status = 1 - my_img_status ;this will toggle between 0 and 1 endif endif if my_img_status = 1 then drawimage my_img,my_imgx,my_imgy endif DrawImage pointer, mx, my flip wend [/code] |
| ||
Thanks for the help, sorry about that just that when i comes to putting pieces of code together i'm not use but programing from scratch i'm quite good at. thanks again. |
| ||
One thing everyone's been missing is that there is nothing in the sample code to blank out the picture when STATUS=0, which is Goober's problem currently. He needs something like: if my_img_status = 0 then drawimage blankimage,my_imgx,my_imgy endif just before the drawimage pointer statement at the end. That should give him what he wants- toggling the image on and off. Goober: put the handle of your original image in the above IF statement in place of the "blankimage" handle so it will draw the original image back when you click the mouse the second time over the picture (when STATUS=0). |
| ||
Hows it looking Goober? |