Highlighting Function
BlitzPlus Forums/BlitzPlus Beginners Area/Highlighting Function
| ||
I made this function- Function Highlight() If ImageRectOverlap(mouse,MouseX(),MouseY(),300,250,205,31) Then DrawImage new1,200,200,0 EndIf End Function And it doesn't work for what I want it to do, infact it doesn't work at all. |
| ||
Did not test, but it should work ( I never used ImageRectOverlap ) :Global new1%=0 Global mouse%=0 new1=LoadImage blabla... mouse=LoadImage blabla... Function Highlight(a1%,a2%,a3%,a4%,a5%,a6%,a7%) If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7) DrawImage new1,200,200,0 EndIf End Function ;in game Highlight(mouse,MouseX(),MouseY(),300,250,205,31) |
| ||
Much thanks, Reno; I just got one more question, what are the a1,a2,a3,a4,a5,a6 for? Just wondering. Also, If this is my code Then lets say I want to have the program loop me to the part the mouse is on (for example, new game) when the collision's detected and MouseDown then how would I do that with a While/Wend loop? |
| ||
use (code) (/code) or (codebox) (/codebox) tags for your code -replace the ( ) with [ ] when you do- |
| ||
Could you show me a example? |
| ||
o_O If I do that you can't see the tags.. :P Erhm, it's forum-codes eh, not Blitz-code! I'm talking about pasting code here.. See? Print "w000t" and -between tags- Print "w000t" |
| ||
Ok, fine I'll work it out by myself |
| ||
Can someone please tell me what "undefined label" means, it keeps on coming up with my label even though I got the .label thing. Any suggestions? |
| ||
For the function, read the doc online or hightlight a word and type twice F1 in BLITZ IDE. "undefined label" ? Show your code... |
| ||
Here's the code NOTE: Just a work-in-progress ok? Happy?====> EDITED TWICE |
| ||
again: Do us a favour: and put your code between (code) (/code) tags (replace () with [] ) .. it reads so much better, and indenting is preserved) |
| ||
You are right...use the forum tags when posting ! Siopses >It seems that we can't use Goto and the label outside the function. Find another way to do that ! |
| ||
O.k thanks for the information, but how am I supposed to make a function to make it possible to simply click on the (for example) 'new game' image to go to a new game. |
| ||
Goto is evil anyway, it's the highway to Italian Pasta, use functions all the way. Here's pseudocode, I'm kinda used to event-based code and apps, I ditched Graphics modes ever since I started out with B+ :P If MouseX()>=NewGameImageX1 and MouseX()<=NewGameImageX2 and MouseY()>=NewGameImageY1 and MouseY()<=NewGameImageY2 ^ if this is true, then your pointer is in the new game image next, check for a key/mouse/joystick trigger, et voila: you may now call a function called Game(). In this Game() runs your game! Ok, enough chaos for now, and perhaps you can't make soup from it still :P .. I've a bloody deadline to make ._. |
| ||
Here is a very basic of what I do :event%=0 cls select event ;screen to click on NEWGAME case 0 if "click is true" event=1 endif ;screen that show level info case 1 drawimage blabla if "time or loop">"5 seconds" event=2 endif ;in game case 2 "your game loop" end select flip |
| ||
I don't quite understand programming events yet. |
| ||
"event" is just the name of the variable... nothing to go with the BLITZplus event system... |
| ||
I know, what I mean is the set-up of an event. Like CASE and every thing else. |
| ||
truly: this is just too funny :P You replaced all your () with [] in your source. I mentioned before that I was talking forum-codes, not Blitz-code. So, I meant that you put your sourcecode between forumcode tags, namely: (code) and (/code) or (codebox) and (/codebox). The reason I say 'replace () with []' is because I can't type (code) or (codebox) because it then makes a codebox .. and the command disappears from a post then. So, leave your blitzsourcecode as it is, but put it between tags! It reads a lot better for the people who try to help you. About your code: it's not the right way to do this thing. You never make functions like those to check for specific menu items (well, obviously you could, but you want to learn proper code, do you?) In your example you're linking the technical concept of 'a menu' with the actual visual implementation, which is not something you should do. What you should try to do is: - make code that displays *any* menu, of any size with any amount of menu choices, anywhere on the screen - define your menu content (newgame, options, quit etc.) somewhere else, but *not in the menu code!* So, how to start? Divide your menu into two parts: - a technical list, which is purely a list of menu options. Note that you should know the length of this list. How you'll be implementing that is up to you. I'd put it in a bank orso, but you could also make some global array$ and a global value for the length of this array.. it's just that I don't like globals .. :P You could also store the amount of menu items in the first array item.. then you only need one array! Anyway, that's up to you again. - make a visual displayer for this technical list. This displayer should of course be able to display any list you made, as long as the list technically works the same. This displayer should have properties like: x, y, width, height, itemheight, maxitems, currentoption .. and another bunch o' stuff. Probably a lot of stuff for -I estimate :P- a beginner, but you gotta start somewhere, eh.. Best tip I can give tho is to start slowly, a game is about the most tricky thing one can make. Start easy/slowly with small dull things, learn bit by bit, try to learn to think ahead, try to envision what will happen when you code into a certain direction instead of another direction. |
| ||
Thanks for the information, but I seriously have no clue what you mean when you say So, I meant that you put your sourcecode between forumcode tags, namely: (code) and (/code) or (codebox) and (/codebox). |
| ||
ok, plan B:[code] Graphics 640,480 Print "OMFG!" End[/code] Did you ever use any forum before? Regular forums for news/reactions etc.? |
| ||
[ c o d e ] Print "if it works, you should only need to move the spaces in these tags" [/ c o d e ] |
| ||
Just forget about okay I don't need this damn forum's help anyway. |
| ||
ok, to make a codebox, just use [code] to start it and [/code] to end it it produces this effect: This is in a codebox details at: http://www.digit-life.com/forum/help/code.html |
| ||
I can't run without the pics, but does not generate any errors from "Check for errors F7" in "Program" menu.Graphics 800,600 ;Images COE=LoadImage("cube_of_evil.bmp") hand=LoadImage("hand.bmp") title=LoadImage("title.bmp") Xbound=LoadImage("X-boundary") Ybound=LoadImage("Y-boundary") mouse=LoadImage("mouse.bmp") new0=LoadImage("newgame.bmp") highscore0=LoadImage("highscore.bmp") Global highscore1=LoadImage("highscore1.bmp") options0=LoadImage("options.bmp") Global options1=LoadImage("options1.bmp") Global neww=LoadImage("newgame1.bmp") ;Fonts fntArial=LoadFont("Arial",48,False,True,False) fntbroadway=LoadFont("Broadway",36,False,False,False) fntgameover=LoadFont("Chiller",48,True,True,False) ;================ Global ExitFlag% ;<- added this ;================ While Not KeyDown(1) ; SetFont fntArial ;this font is not used here Color 0,0,255 ;menu SetFont fntbroadway Cls DrawImage title,200,0 DrawImage new0,300,250,0 DrawImage highscore0,300,300,0 DrawImage options0,300,350,0 DrawImage mouse,MouseX(),MouseY() HighlightNewGame(mouse,MouseX(),MouseY(),300,250,205,31) HighlightHighScore(mouse,MouseX(),MouseY(),300,300,205,31) HighlightOptions(mouse,MouseX(),MouseY(),300,350,205,31) Delay 25 Flip ;============================ If ExitFlag = 1 Then Exit ;<- added this ;============================ Wend End Function HighlightNewGame(a1%,a2%,a3%,a4%,a5%,a6%,a7%) If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7) DrawImage neww,300,250,0 End If End Function Function HighlightHighScore(a1%,a2%,a3%,a4%,a5%,a6%,a7%) If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7) DrawImage highscore1,300,300,0 End If End Function Function HighlightOptions(a1%,a2%,a3%,a4%,a5%,a6%,a7%) If ImageRectOverlap(a1,a2,a3,a4,a5,a6,a7) DrawImage options1,300,350,0 End If End Function Function Click1(HighlightNewGame) If MouseDown(1) And HighlightNewGame = 1 Then ; Goto .newgame ;this label does not exist outside of this function as far as Blitz is concerned ;=================== NewGame() ;changed label to function and added ExitFlag ExitFlag = 1 ;=================== End If End Function ;========================== ;changed your label into a function Function NewGame() Text 400,300,"NEW GAME" Delay 5000 End Function ;========================== To make codebox like the one above do the following: STEP 1: [-code] <---- copy this paste into Blitz forum window erase minus sign from what you pasted into Blitz forum window STEP 2: Paste your code right after where you pasted step 1 (or skip this if editing an existing post) STEP3: [/code] <---- copy this erase minus sign from what you pasted into Blitz forum window paste into Blitz forum window immediately after your pasted or edited source code See forum codes here: http://www.blitzbasic.com/faq/faq_entry.php?id=2 [Edited to reflect Senzak's make bold suggestion - but it didn't work :\ ] |
| ||
it's easier to demonstrate the concept if you bold the word code (using [b] and [/b]), then it doesn't create the codebox |
| ||
I think it's too late anyway, judging his last reply .. :P |
| ||
yeah, that's too bad though...... |
| ||
Thank you, Senzak for putting it into understandable words. Also thanks to Andy_A, and to CS_TBL look at my past coding now! ;) All my current programing problems have now been resolved, Thank you all! |
| ||
Hold that thought, the coding that Andy_A edited for me does not work, As Reno said: "It seems that we can't use Goto and the label outside the function. Find another way to do that !" I don't think that the program will work this way :( |
| ||
"Goto" was commented out since labels are not seen when outside of a function. Modified snippet uses function called "NewGame" |
| ||
It doesn't even work when I ran it, I think I'll forget about this project. |
| ||
Maybe try this then? |
| ||
That's all right, thanks! :) |
| ||
Sorry, for some odd reason StringHeight(i$) is not working, it says "function stringheight not found." |
| ||
That could be a b3d function then, maybe replace it with 30 (size of the font) ? |
| ||
Odd. If you're using BlitzPlus there shouldn't be an issue with using StringHeight. I'm fairly sure that function is available, as its even listed in the current online manuals for it. |
| ||
Could I post this into Blitz Plus Bug's? |
| ||
Yes, I don't think it should be missing. I tried it with the demo, and the command is recognized. |