Problem mit MouseHit...
Übersicht BlitzBasic Beginners-Corner
DüsiBetreff: Problem mit MouseHit... |
Do, Mai 08, 2008 17:43 Antworten mit Zitat |
|
---|---|---|
Moin,
ich versuche gerade ein einfaches Mal-Programm zu machen. Jetzt will ich, damit wenn man eine Farbe wo aufgelistet wird anklickt, er sie übernimmt. Dafür habe ich folgendes: Code: [AUSKLAPPEN] Function colorselection(x, y, x2, y2, hexcode$)
If MouseX() > x And MouseX() < x2+x And MouseY() > y And MouseY() < y2+y Then If MouseHit(1) Then ;<-- Das will nicht klappen selectcolor = hexcode$ Else selectcolor = selectcolor EndIf Else selectcolor = selectcolor End If End Function Wenn ich jetzt über eine Farbe mit der Maus fahre, übernimmt er sie so wie es sein soll, ABER er übernimmt sie auch wenn ich nicht darauf klicke sondern nur mit der Maus darübert fahre. Der gesammte Code: (Ja, vieles ist sicherlich komisch gemacht, ich bin eben ein noob ) Code: [AUSKLAPPEN] ;GRAFIKEINSTELLUNGEN
screenx = 640 ;Breite screeny = 480 ;Höhe colormode = 16 ;Farbtiefe displaymode = 2 ;Fenstermodus Graphics screenx, screeny, colormode, displaymode SetBuffer BackBuffer() ;VARIABLEN Global selectcolor$ = "255, 255, 255" ;HAUPTSCHLEIFE Repeat If KeyHit(59) Then reset tools() ;Werkzeuge laden colorcode(selectcolor) ;Richtige Farbe auswählen If MouseDown(1) And MouseY() < 460 Then Plot MouseX(), MouseY() End If Flip Until KeyHit(1) End ;Programm beenden ;FUNCTIONEN Function tools() ;Abtrennungen colorcode(0) ;Farbe auf weiß setzten Line -1, 460, 641, 460 ;Farben colors(1, 465, 10, 10, "0, 0, 255") ;Blau colors(15, 465, 10, 10, "0, 255, 0") ;Grün colors(30, 465, 10, 10, "255, 0, 0") ;Rot End Function Function reset() ;Alles gemalte löschen Cls tools() ;Und die Tools wieder hinmalen End Function Function colors(x, y, x2, y2, hexcode$) ;Farben colorcode(hexcode) ;Fabre heraussuchen Rect x, y, x2, y2, 1 ;Rechteck mit der Farbe zeichnen colorselection(x, y, x2, y2, hexcode$) ;Die Funktion um die Farbe auszuwählen End Function Function colorselection(x, y, x2, y2, hexcode$) If MouseX() > x And MouseX() < x2+x And MouseY() > y And MouseY() < y2+y Then If MouseHit(1) Then selectcolor = hexcode$ Else selectcolor = selectcolor EndIf Else selectcolor = selectcolor End If End Function Function colorcode(hexcode$) ;Mit einem Hexcode die Farbe auswählen Select hexcode Case "0, 0, 255" ;Farbe: Blau Color 0, 0, 255 Case "0, 255, 0" ;Farbe: Grün Color 0, 255, 0 Case "255, 0, 0" ;Farbe: Rot Color 255, 0, 0 Default Color 255, 255, 255 End Select End Function |
||
RallimenSieger des 30-EUR-Wettbewerbs |
Do, Mai 08, 2008 18:04 Antworten mit Zitat |
|
---|---|---|
Die Antwort ist relativ einfach..
Beim malen drückst du doch die Mousetaste und erzeugst damit ein Mousehit und solange du Mousehit nicht abfragst wird der Puffer nicht auf 0 gesetzt. Wenn du dann deine Maus auf die Farbwahl bewegst ist mousehit() <> 0 und die Farbe wird gewechselt Lösung: Globale Variable erstellen und die in der Hauptschleife mit Mousehit () belegen Jetzt kannst du in jeder Function die Globale Var nutzten und anstatt Moushit die Var abfragen... die Probleme sind damit gelöst . |
||
[BB2D | BB3D | BB+]
|
WEBLink |
Do, Mai 08, 2008 18:08 Antworten mit Zitat |
|
---|---|---|
Nimm eine Variable nenn sie "mousehit_" globalisiere sie und weise ihr in deiner Hauptschleife die linke Maustaste zu. Frage dann MouseHit_ ab und das wars.
Obwohl ich sagen muss das du alles sehr umständlich geschrieben hast. Und ganz nebenbei ein richtiges Malprogramm wird das wohl nie werden Edit: langsam nervt es das ich immer so lange zum schreiben brauch-.- Code: [AUSKLAPPEN] ;GRAFIKEINSTELLUNGEN
screenx = 640 ;Breite screeny = 480 ;Höhe colormode = 16 ;Farbtiefe displaymode = 2 ;Fenstermodus Graphics screenx, screeny, colormode, displaymode SetBuffer BackBuffer() ;VARIABLEN Global selectcolor$ = "255, 255, 255" Global MouseHit_ ;HAUPTSCHLEIFE Repeat mousehit_ = MouseHit(1) If KeyHit(59) Then reset tools() ;Werkzeuge laden colorcode(selectcolor) ;Richtige Farbe auswählen If MouseDown(1) And MouseY() < 460 Then Plot MouseX(), MouseY() End If Flip Until KeyHit(1) End ;Programm beenden ;FUNCTIONEN Function tools() ;Abtrennungen colorcode(0) ;Farbe auf weiß setzten Line -1, 460, 641, 460 ;Farben colors(1, 465, 10, 10, "0, 0, 255") ;Blau colors(15, 465, 10, 10, "0, 255, 0") ;Grün colors(30, 465, 10, 10, "255, 0, 0") ;Rot End Function Function reset() ;Alles gemalte löschen Cls tools() ;Und die Tools wieder hinmalen End Function Function colors(x, y, x2, y2, hexcode$) ;Farben colorcode(hexcode) ;Fabre heraussuchen Rect x, y, x2, y2, 1 ;Rechteck mit der Farbe zeichnen colorselection(x, y, x2, y2, hexcode$) ;Die Funktion um die Farbe auszuwählen End Function Function colorselection(x, y, x2, y2, hexcode$) If MouseX() > x And MouseX() < x2+x And MouseY() > y And MouseY() < y2+y Then If mousehit_ Then selectcolor = hexcode$ Else selectcolor = selectcolor EndIf Else selectcolor = selectcolor End If End Function Function colorcode(hexcode$) ;Mit einem Hexcode die Farbe auswählen Select hexcode Case "0, 0, 255" ;Farbe: Blau Color 0, 0, 255 Case "0, 255, 0" ;Farbe: Grün Color 0, 255, 0 Case "255, 0, 0" ;Farbe: Rot Color 255, 0, 0 Default Color 255, 255, 255 End Select End Function |
||
Düsi |
Do, Mai 08, 2008 18:13 Antworten mit Zitat |
|
---|---|---|
Dankeschön .
Damits nie ein richtiges Maleprogramm wird ist mir klar . |
||
panky |
Do, Mai 08, 2008 19:26 Antworten mit Zitat |
|
---|---|---|
da gibts doch bestimmt auch sowas wie "flushkeys" für die tastatur. ich weiß es leider nicht aus dem kopf, aber rein der logik nach könnte es "flushmouse" sein. mit diesem befehl wird halt der puffer gelöscht und das problem ist geschichte. | ||
Übersicht BlitzBasic Beginners-Corner
Powered by phpBB © 2001 - 2006, phpBB Group