NEWB Questions~ Nyo~
Blitz3D Forums/Blitz3D Beginners Area/NEWB Questions~ Nyo~
| ||
Okay, how would you do it: 1) On mouse over do this: 2) Change the cursor 3) Replace an image with another image All comes to MouseOver buttons. |
| ||
[pseudocode]HidePointer Load Default Mouse Cursor (using LoadImage) Load Alternate Mouse Cursor >Start main loop draw button images Draw Default Mouse Cursor at mouse coords (using DrawImage) Test collision between Mouse Cursor Image and Button Images If Collided then Change Mouse Image Change Image Mouse collided with endif <End Main Loop [/pseudocode] Perhaps use types to track the button and mouse states |
| ||
I really don't understand your code.. |
| ||
It's not code, it's psuedocode (i.e. a basic run down of what you need to do in order to get it working). |
| ||
Ah... but as I don't know some of the code, can anyone give me the codes i need? |
| ||
HidePointer DefaultMouseCursor = LoadImage{"DefMouseCur") AlternateMouseCursor = LoadImage{"AltMouseCur") CurrentMouseCursor = DefaultMouseCursor ;button1 = LoadImage("button1") ;button1X = blah ;button1Y = blah ;Start main loop ;draw button images DrawImage CurrentMouseCursor, MouseX(), MouseY() If RectsOverlap(CurrentMouseCursor, MouseX(), MouseY(), Button1, button1X, button1Y) CurrentMouseCursor = AlternateMouseCursor ;Change button Image Mouse collided with else CurrentMouseCursor = DefaultMouseCursor ;Change button Image back to default endif ;End main loop Note that the button parts are still pseudo code |
| ||
Ah... but as I don't know some of the code, can anyone give me the codes i need? Look at what Perturbatio wrote above. It's not true litteral Blitz code, but it describes the steps nessecary to acheive what you want.!! Warning Spoilers Ahead !! HidePointer myMouse = LoadImage("myMouseImage.png") myAltMouse = LoadImage("myAlternativeMouseImage.png") myButton = LoadImage("myButtonImage.png") myAltButton = LoadImage("myAlternativeButtonImage.png") myCurrentButton = myButton myCurrentMouse = myMouse While Not (KeyHit(1)) DrawImage myCurrentButton,0,0 DrawImage myCurrentMouse,MouseX(),MouseY() If ImagesOverlap(myCurrentButton,0,0,MyCurrentMouse,MouseX(),MouseY()) myCurrentButton = myAltButton myCurrentMouse = myAltMouse Else myCurrentButton = myButton myCurrentMouse = myMouse EndIf EndIf WendThis version is (more or less) the litteral Blitz code you would type to implement Perturbatio's pseudo code example above. You would be doig yourself an *enormous* favor by figureing out *why* it works (and not just being happy with *that* it works). Programming is all about solving problems of this kind, and the only way to learn is by experience. Incidently I haven't actually tested the code above in Blitz, but it should work (although you may have to run the program in debug mode if you're using BlitzPlus). |
| ||
FlameDuck, you have an extra Endif at the end of your UnPseudoCode. Btw, it is interesting that your code is eerily similar to mine. |
| ||
Im using blitzplus, thanks for the code! And yes I learn from code I'm not just happy with what it does, I like to know exactly what every line of code is for. I used other game programming tools before the language is different but it quite comes down to the same thing.. "'if' this 'DO' that 'ELSE' this" or "if this { do this } else { this }" Pretty much the same, you just goto know the syntax and tahst what im trying to learn :) Anyhow I'll test the code tommorow and post here if I figure it all and if not ill post question in here again ;) Sorry cause its almost 5 am and im suppose to sleep ;) cya |
| ||
Ok, the CURSOR doesnt show and I dunno why :*(Cls Flip While Not KeyHit(1) ; START HidePointer ;------------------------------- ; MAIN SCREEN ;------------------------------- If drawMain = True Then DrawImage myMouse ,MouseX(),MouseY() DrawImage MBackground01 ,0 ,0 DrawImage MMenu01 ,300,200 DrawImage MSi ,318,220 DrawImage MMu ,318,255 DrawImage MOp ,318,290 DrawImage MCr ,318,325 DrawImage MQu ,318,360 Flip Else Cls Flip End If If KeyDown(2) Then drawMain = False EndIf If KeyDown(3) Then drawMain = True EndIf ; END Wend I dont get why it doesnt show the cursor can u guys help? |
| ||
So Keydown(3) (pressing "2") will activate the Cursor? |
| ||
You might want to use a cls after the flip when drawMain is true (otherwise you will be drawing multiple copies of anything that moves).Cls Flip While Not KeyHit(1) ; START HidePointer ;------------------------------- ; MAIN SCREEN ;------------------------------- If drawMain = True Then DrawImage myMouse ,MouseX(),MouseY() DrawImage MBackground01 ,0 ,0 DrawImage MMenu01 ,300,200 DrawImage MSi ,318,220 DrawImage MMu ,318,255 DrawImage MOp ,318,290 DrawImage MCr ,318,325 DrawImage MQu ,318,360 Flip Cls Else Cls Flip End If If KeyDown(2) Then drawMain = False EndIf If KeyDown(3) Then drawMain = True EndIf ; END Wend end |
| ||
@(jfk): ya actually the variable is set to true by default, I was just testing if I could erase it quickly, and redraw it quickly, just for testing purpose :) ------------- For the cursor, the cursor is still invisible I don't see it at all :( Something must be wrong? |
| ||
It might help if you flipped the buffers ( Flip ) after you've done the drawing. At the moment, you're clearing the screen and flipping it. So you see nothing ( unsurprisingly. ) |
| ||
LOL I found what was wrong, I drew it before the other drawings so, it was behind the other graphics and that is why I couldnt see it :S Wouldnt using a depth command when u draw stuff be easyer, like DrawImage MyImage,0,0,depth$ Code example: DrawImage MyImage1,0,0,0 DrawImage MyImage2,0,0,1 So MyImage2 would be infront of MyImage1, it would be much easyer to set up stuff, no? |
| ||
Maybe - but it would also make things more complicated. The way it works at the moment it's like a real World model, eg: your Desk: you put a lot of stuff onto your desk, then watch it from above. |
| ||
Yeah but think about it you could put your drawimage fonction anywhere |
| ||
Mouse Over Button doesnt work can u guys help me, thanks in advance :)If drawMain = True Then DrawImage MBackground01 ,0 ,0 DrawImage MMenu01 ,300,200 DrawImage MSingleplayer ,318,220 DrawImage MMultiplayer ,318,255 DrawImage MOptions ,318,290 DrawImage MCredits ,318,325 DrawImage MQuit ,318,360 End If CurrentSingle_Button = MSingleplayer OverSingle_Button = MSingleplayerOVER CurrentMouse = myMouse If ImagesOverlap(CurrentSingle_Button,0,0,CurrentMouse,MouseX(),MouseY()) CurrentSingle_Button = OverSingle_Button EndIf DrawImage CurrentMouse ,MouseX(),MouseY() Flip Cls |
| ||
Try not to overcomplicate itCurrentSingle_Button = DefaultSingle_Button while not keydown(1) cls If ImagesOverlap(CurrentSingle_Button,0,0,CurrentMouse,MouseX(),MouseY()) CurrentSingle_Button = OverSingle_Button else CurrentSingle_Button = DefaultSingle_Button EndIf drawimage CurrentSingle_Button,x,y DrawImage CurrentMouse ,MouseX(),MouseY() flip wend |
| ||
FlameDuck, you have an extra Endif at the end of your UnPseudoCode. LOL! That's what happens when you're not allowed to use squigly brackets. :o> Btw, it is interesting that your code is eerily similar to mine. I dunno about you, I just did a line by line conversion of the pseudo code. If you did roughly the same, I reckon that would explain it. :o> |
| ||
My code keeps crashing as its not working very well.. |
| ||
Umm, well fix it then. Statements such as the one you just posted don't help me in any way help you. Be more specific. |
| ||
I was able to fix the crashing part. However the mouseover buttons still wont work, so i decided to show my entire code: AppTitle "Practice" Graphics 800, 600, 16, 2 SetBuffer BackBuffer() ;------------ ; Global Variables ;------------ Global drawMain = True ;------------ ; Global LoadImage ;------------ ; START ||| FIRST SCREEN - MENU Global MLogo = LoadImage("graphics\main_logo.png") Global myMouse = LoadImage("graphics\defaultcursor.png") Global myAltMouse = LoadImage("graphics\overcursor.png") Global MMenu01 = LoadImage("graphics\main_menu01.png") Global MSingleplayer = LoadImage("graphics\main_singleplayer.png") Global MMultiplayer = LoadImage("graphics\main_multiplayer.png") Global MOptions = LoadImage("graphics\main_options.png") Global MCredits = LoadImage("graphics\main_credits.png") Global MQuit = LoadImage("graphics\main_quit.png") Global MBackground01 = LoadImage("graphics\main_background.png") Global MSingleplayerOVER = LoadImage("graphics\main_singleplayerOVER.png") ; END ||| FIRST SCREEN - MENU ;------------ ; Types ;------------ ;------------ Cls:Flip While Not KeyHit(1) ;-------------------------------; ;------- MAIN CODE HERE --------; ;-------------------------------; HidePointer ;-------------------------------; ;--------- MAIN SCREEN ---------; ;-------------------------------; If drawMain = True Then DrawImage MBackground01 ,0 ,0 DrawImage MLogo ,200,701 DrawImage MMenu01 ,300,200 DrawImage MSingleplayer ,318,220 DrawImage MMultiplayer ,318,255 DrawImage MOptions ,318,290 DrawImage MCredits ,318,325 DrawImage MQuit ,318,360 End If CurrentSingle_Button = MSingleplayer CurrentMouse = myMouse If ImagesOverlap(CurrentSingle_Button,318,220,CurrentMouse,MouseX(),MouseY()) CurrentSingle_Button = MSingleplayerOVER Else CurrentSingle_Button = MSingleplayer EndIf DrawImage CurrentMouse ,MouseX(),MouseY() Flip Cls ;--------------------------------; ;----------- MAIN END -----------; ;--------------------------------; ; Test If KeyDown(2) Then drawMain = False EndIf If KeyDown(3) Then drawMain = True EndIf ;-------------------------------- ; END Wend If you can fix it please tell me. And please be specific on how to fix it :| Thanks. |
| ||
The reason it's not working is because you're drawing the wrong image. You're drawing MSingleplayer, you should be drawing CurrentSingle_Button. Also you have quite a lot of redundant instructions in there. For example, you don't need to HidePointer every frame, nor do you need to reset CurrentSingle_Button, if the images don't collide, since you've already reset it above the If statement. |
| ||
I don't understand. |
| ||
You need a drawimage command that draws the image CurrentSingle_Button NOT MSingleplayer Although you are assigning MSingleplayer to CurrentSingle_Button they are in effect two different images for the purposes of collision testing. |
| ||
Hmmm, but isnt CurrentSingle_Button = MSingleplayer so arent they the same? |
| ||
I could write a=5 b=a although both a and b are equal to five, they are not the same variables. |
| ||
maybe this works:HidePointer CurrentSingle_Button = MSingleplayer While Not KeyHit(1) ;-------------------------------; ;------- MAIN CODE HERE --------; ;-------------------------------; ;--------- MAIN SCREEN ---------; ;-------------------------------; If drawMain = True Then DrawImage MBackground01 ,0 ,0 DrawImage MLogo ,200,701 DrawImage MMenu01 ,300,200 DrawImage CurrentSingle_Button ,318,220 DrawImage MMultiplayer ,318,255 DrawImage MOptions ,318,290 DrawImage MCredits ,318,325 DrawImage MQuit ,318,360 End If CurrentSingle_Button = MSingleplayer CurrentMouse = myMouse If ImagesOverlap(CurrentSingle_Button,318,220,CurrentMouse,MouseX(),MouseY()) CurrentSingle_Button = MSingleplayerOVER Else CurrentSingle_Button = MSingleplayer EndIf DrawImage CurrentMouse ,MouseX(),MouseY() Flip Cls ;--------------------------------; ;----------- MAIN END -----------; ;--------------------------------; ; Test If KeyDown(2) Then drawMain = False EndIf If KeyDown(3) Then drawMain = True EndIf ;-------------------------------- Wend but with the line: If ImagesOverlap(CurrentSingle_Button,318,220,CurrentMouse,MouseX(),MouseY()) I am not shure if you really need to use "318,220" and not maybe Zero,zero as an Offset (?) |
| ||
Nope says "Duplicate Variable name" |
| ||
You also appear to be assigning a value to CurrentMouse and CurrentSingle_Button in the loop, so it will always default to that try commenting out the line: CurrentSingle_Button = MSingleplayer |
| ||
tryed nothing works damnit, how hard can it be. Ill find a freaken way if its the last thing i do. |
| ||
Finnally Succeded after trying, trying, trying. I created a new project re did the code as I was getting mixed up with the other code. The code i came up with is not very high tech code but it does the job. Might have bad code in it if theres is tell me :) Im gonna play with it to see what we were doing wrong. Oh and heres the code: AppTitle "Practice" Graphics 800, 600, 16, 2 SetBuffer BackBuffer() Global arrow = LoadImage("graphics\defaultcursor.png") Global Single1 = LoadImage("graphics\main_singleplayer.png") Global Single2 = LoadImage("graphics\main_singleplayerOVER.png") HidePointer While Not KeyHit(1) If ImagesOverlap(Single1,100,0,arrow,MouseX(),MouseY()) Cls DrawImage Single2,100,0 Else Cls DrawImage Single1,100,0 EndIf DrawImage arrow,MouseX(),MouseY() Flip:Cls Wend -------------------EDITED And this is the second way I found how to do it, I think this way should be better, its almost like the old one that didnt work so well, or it is the old. But Anyhow here it is, is it better or not from the one above? AppTitle "Practice" Graphics 800, 600, 16, 2 SetBuffer BackBuffer() Global arrow = LoadImage("graphics\defaultcursor.png") Global Single1 = LoadImage("graphics\main_singleplayer.png") Global Single2 = LoadImage("graphics\main_singleplayerOVER.png") Sin1 = Single1 Sin2 = Single2 arr1 = arrow HidePointer While Not KeyHit(1) If ImagesOverlap(Sin1,100,0,arr1,MouseX(),MouseY()) BUTTON = Sin2 Else BUTTON = Sin1 EndIf DrawImage BUTTON,100,0 DrawImage arr1,MouseX(),MouseY() Flip:Cls Wend I have to say you guys, your help is very appreciated, I bet when I get to making my char move on the screen and making maps for it, my future help post is gonna hit +100 post ;) |
| ||
"I have to say you guys, your help is very appreciated, I bet when I get to making my char move on the screen and making maps for it, my future help post is gonna hit +100 post ;)" Nah! That stuff's a piece of cake. Once you get a way of storing the map the rest just falls into place. Just FYI, I use the same method as your first overlap example for Trouble's menu system (but with some sfx bundled in for good measure). Since ImagesOverlap is faster than ImagesCollide you could have hundreds of buttons with little or no speed loss. Here's the code if you're interested. ; Create a pointer image. Since Trouble runs in a window, I use ; a pixel size image for overlap so I can keep the default Windows mouse pointer. point = CreateImage(1,1) ; ... Then in the main loop click = MouseHit(1) no_overlap = True If ImagesOverlap(point, MouseX(), MouseY(), sngle, 207, 241) DrawImage sngle_sel, 207, 241 Color 0, 0, 255 Rect 207, 241, ImageWidth(sngle), ImageHeight(sngle), 0 ; The last_overlap variable assures sound is only played once on hover If last_overlap <> 1 PlaySound snd_hover last_overlap = 1 If click goption = 1 snd_channel = PlaySound(snd_click) EndIf ; The no_overlap variable when True means the cursor is not ; over a button. So play a sound next time it hovers over. no_overlap = False Else DrawImage sngle, 207, 241 EndIf If no_overlap last_overlap = 0 EndIf |
| ||
Hmmm, but isnt CurrentSingle_Button = MSingleplayer Yes, but you where drawing MSinglePlayer, the variable that is *always* the same (it's the handle of the loaded image). You where changing CurrentSingle_Button, that's what you should have used.so arent they the same? I would prefer to use the second one, although you've still got some redundant code. There's no need to have multiple variables for values that never change. Such as "Sin1 = Single1","Sin2 = Single2" and "arr1 = arrow". |
| ||
Ahahaha FlameDuck forgot to change that part back cause I was checking something ;) |
| ||
lmao >.> Im trying to impliment the second code I made above but I get "Bad Image Handler" its soo funny cause I can't understand why XD |
| ||
Got it >.> Well, I guess B+ reads the code from TOP to BOTTOM so what I did wrong is put the drawing event before the "IF MOUSE OVER EVENT" ... So anyhow I finnally did it :S |
| ||
Well, I guess B+ reads the code from TOP to BOTTOM Which isn't really that unusual when compared to every other programming language in the world ever. :o> So anyhow I finnally did it :S Congratulations. I think. :o> |
| ||
Maybe I would become famous for writing a complier that reads from BOTTOM to TOP? ;) |
| ||
lolll! What about a compiler who you let the user chose XD |