aus und einrastfunktion funktioniert nicht richtig

Übersicht BlitzBasic Allgemein

Neue Antwort erstellen

draco

Betreff: aus und einrastfunktion funktioniert nicht richtig

BeitragSa, Aug 18, 2007 15:55
Antworten mit Zitat
Benutzer-Profile anzeigen
hi
ich habe ein problem mit einer "aus und einrastfunktion" sozusagen...

ich habe folgenden code:

Code: [AUSKLAPPEN]
Graphics 400,200,0,2
SetBuffer BackBuffer()




vol1is=1
vol2is=1
vol3is=1
vol4is=1
vol5is=1


;===Main-Loop===
While Not KeyHit(1)



Color 0,0,$003869 : Rect 0,0,400,200
Color 0,0,$FFFFFF : Rect -1,20,402,40,0




;Vol 1
If MouseX() > 10 And MouseX() < 30 And MouseY() > 110 And MouseY() < 120 And MouseHit(1) Then
vol1is = 1-vol1is
EndIf
;Vol 2
If MouseX() > 35 And MouseX() < 55 And MouseY() > 100 And MouseY() < 120 And MouseHit(1) Then
vol2is = 1-vol2is
EndIf
;Vol 3
If MouseX() > 60 And MouseX() < 80 And MouseY() > 90 And MouseY() < 120 And MouseHit(1) Then
vol3is = 1-vol3is
EndIf
;Vol 4
If MouseX() > 85 And MouseX() < 105 And MouseY() > 80 And MouseY() < 120 And MouseHit(1) Then
vol4is = 1-vol4is
EndIf
;Vol 5
If MouseX() > 110 And MouseX() < 130 And MouseY() > 70 And MouseY() < 120 And MouseHit(1) Then
vol5is = 1-vol5is
EndIf

Color vol1_1,vol1_2,vol1_3 : Rect 10,110,20,10   ;<--- Vol 1
Color vol2_1,vol2_2,vol2_3 : Rect 35,100,20,20   ;<--- Vol 2
Color vol3_1,vol3_2,vol3_3 : Rect 60,90,20,30   ;<--- Vol 3
Color vol4_1,vol4_2,vol4_3 : Rect 85,80,20,40   ;<--- Vol 4
Color vol5_1,vol5_2,vol5_3 : Rect 110,70,20,50   ;<--- Vol 5
Color 200,200,200




Text 10,160,"1= "+vol1is+" | 2= "+vol2is+" | 3= "+vol3is+" | 4= "+vol4is+" | 5= "+vol5is

Flip

Wend
End


eigentlich müsste bei jedem klick auf ein enstprechendes rechteck die zahl von 1 auf 0 wechseln bzw. von 0 auf 1. leider funktioniert das nur beim 1. rechteck. wieso??

eine antwort darauf würde mir sehr weiterhelfen

ich danke schonmal im vorraus Smile

X-Calibur

BeitragSa, Aug 18, 2007 16:13
Antworten mit Zitat
Benutzer-Profile anzeigen
hi, dein Problem ist mousehit()
Das lässt sich pro durchlauf nämlich nur einmal abfragen. Entweder abfangen und in einer Variable speichern oder so wie in deinem von mir modifiziertem Beispiel.

Code: [AUSKLAPPEN]
Graphics 400,200,0,2
SetBuffer BackBuffer()


vol1is=1
vol2is=1
vol3is=1
vol4is=1
vol5is=1


;===Main-Loop===
While Not KeyHit(1)



Color 0,0,$003869 : Rect 0,0,400,200
Color 0,0,$FFFFFF : Rect -1,20,402,40,0





If MouseHit(1)
   ;Vol 1
   If MouseX() > 10 And MouseX() < 30 And MouseY() > 110 And MouseY() < 120
      vol1is = 1-vol1is
   EndIf
   ;Vol 2
   If MouseX() > 35 And MouseX() < 55 And MouseY() > 100 And MouseY() < 120
      vol2is = 1-vol2is
   EndIf
   ;Vol 3
   If MouseX() > 60 And MouseX() < 80 And MouseY() > 90 And MouseY() < 120
      vol3is = 1-vol3is
   EndIf
   ;Vol 4
   If MouseX() > 85 And MouseX() < 105 And MouseY() > 80 And MouseY() < 120
      vol4is = 1-vol4is
   EndIf
   ;Vol 5
   If MouseX() > 110 And MouseX() < 130 And MouseY() > 70 And MouseY() < 120
      vol5is = 1-vol5is
   EndIf
EndIf

Color vol1_1,vol1_2,vol1_3 : Rect 10,110,20,10   ;<--- Vol 1
Color vol2_1,vol2_2,vol2_3 : Rect 35,100,20,20   ;<--- Vol 2
Color vol3_1,vol3_2,vol3_3 : Rect 60,90,20,30   ;<--- Vol 3
Color vol4_1,vol4_2,vol4_3 : Rect 85,80,20,40   ;<--- Vol 4
Color vol5_1,vol5_2,vol5_3 : Rect 110,70,20,50   ;<--- Vol 5
Color 200,200,200

mfg X-Calibur

aMul

Sieger des Minimalist Compo 01/13

BeitragSa, Aug 18, 2007 16:14
Antworten mit Zitat
Benutzer-Profile anzeigen
Weil MouseHit() Die Anzahl der Klicks seit dem letzen Aufruf zurückgibt. Und du wirst es wohl kaum hinkriegen genau zwischen zwei If-Abfragen zu klicken.
Du musst den zurückgegebenen Wert zwischenspeichern oder deine If-Konstruktion umbauen, z.B. wie folgt.
Code: [AUSKLAPPEN]
If MouseHit(1) Then
    If lol
        hax = 1 - hax
    EndIf
    If lol2
       hax2 = 1- hax2
    EndIf
    ; ...
Endif


EDIT:
Zu langsam. Dafür ist mein Code lehrreicher Razz
Panic Pong - ultimate action mashup of Pong and Breakout <= aktives Spiele-Projekt, Downloads mit vielen bunten Farben!
advASCIIdraw - the advanced ASCII art program <= aktives nicht-Spiele-Projekt, must-have für ASCII/roguelike/dungeon-crawler fans!
Alter BB-Kram: ThroughTheAsteroidBelt - mit Quelltext! | RGB-Palette in 32²-Textur / Farbige Beleuchtung mit Dot3 | Stereoskopie in Blitz3D | Teleport-Animation Screensaver

draco

BeitragSa, Aug 18, 2007 16:25
Antworten mit Zitat
Benutzer-Profile anzeigen
genial danke!! Smile wie man sieht wird das ne lautstärke regelung Wink
 

D²O

BeitragSa, Aug 18, 2007 16:27
Antworten mit Zitat
Benutzer-Profile anzeigen
Code: [AUSKLAPPEN]
Graphics 400,200,0,2
SetBuffer BackBuffer()




vol1is=1
vol2is=1
vol3is=1
vol4is=1
vol5is=1


;===Main-Loop===
While Not KeyHit(1)

klick = MouseHit(1)
x = MouseX()
y = MouseY()

Color 0,0,$003869 : Rect 0,0,400,200
Color 0,0,$FFFFFF : Rect -1,20,402,40,0




;Vol 1
If x > 10 And x< 30 And y > 110 And y< 120 And klick
vol1is = 1-vol1is
EndIf

;Vol 2
If x > 35 And x < 55 And y > 100 And y < 120 And klick
vol2is = 1-vol2is
EndIf

;Vol 3
If x > 60 And x < 80 And y > 90 And y < 120 And klick
vol3is = 1-vol3is
EndIf

;Vol 4
If x > 85 And x < 105 And y > 80 And y < 120 And klick
vol4is = 1-vol4is
EndIf

;Vol 5
If x > 110 And x < 130 And y > 70 And y < 120 And klick
vol5is = 1-vol5is
EndIf

Color vol1_1,vol1_2,vol1_3 : Rect 10,110,20,10   ;<--- Vol 1
Color vol2_1,vol2_2,vol2_3 : Rect 35,100,20,20   ;<--- Vol 2
Color vol3_1,vol3_2,vol3_3 : Rect 60,90,20,30   ;<--- Vol 3
Color vol4_1,vol4_2,vol4_3 : Rect 85,80,20,40   ;<--- Vol 4
Color vol5_1,vol5_2,vol5_3 : Rect 110,70,20,50   ;<--- Vol 5
Color 200,200,200




Text 10,160,"1= "+vol1is+" | 2= "+vol2is+" | 3= "+vol3is+" | 4= "+vol4is+" | 5= "+vol5is




Flip

Wend
End
Blitz+; Blitz3d; BlitzMax; GLBasic; Purebasic;
GameMaker Studio 1.4xx; AGK;

X-Calibur

BeitragSa, Aug 18, 2007 16:30
Antworten mit Zitat
Benutzer-Profile anzeigen
Das stimmt, amuls code ist lehrreicher, wollte es ihm aber anhand seines Beispiels demonstrieren Smile

Desweiteren würde ich dir noch empfehlen nicht soviele Variablen für den in"" selben Zweck zu erstellen - das macht deinen Code nur unnötig unübersichtlich und bläht ihn auf. Benutze stattdessen lieber ein Array.
z.B Code: [AUSKLAPPEN]
dim VolIs (4,4)

Wobei die erste Dimension für die Anzahl/Index der Balken steht, die 2. mit jeweils 4 Einträgen für die Koordinaten X1,Y1,X2,Y2.
Dann könnte man die Abfrage z.B. auch komplett in einer Schleife durchführen Und dein Code würde auf wenige Zeilen schrumpfen und beliebig viele Balken wären ohne grosses umprogrammieren möglich.

Edit :
Noch ein Beispiel zum besseren Verständnis.
Code: [AUSKLAPPEN]
Graphics 400,200,0,2
SetBuffer BackBuffer()

Vol_Anzahl = 4
Dim Volis ( Vol_Anzahl, 4)

For i = 0 To Vol_Anzahl
   Read d : Volis(i,0)=d ; zustand 0/1
   Read d : Volis(i,1)=d ; X1
   Read d : Volis(i,2)=d ; X2
   Read d : Volis(i,3)=d ; Y1
   Read d : Volis(i,4)=d ; Y2
Next

;===Main-Loop===
While Not KeyHit(1)
MausHit = MouseHit(1)

   Color 0,0,$003869 : Rect 0,0,400,200
   Color 0,0,$FFFFFF : Rect -1,20,402,40,0

   For i=0 To Vol_Anzahl
      If MausHit And MouseX() > Volis(i,1) And MouseX() < Volis(i,2) And MouseY() > Volis(i,3) And MouseY() < Volis(i,4) Then Volis(i,0) = 1-Volis(i,0)   
   Next

   
   Color vol1_1,vol1_2,vol1_3 : Rect 10,110,20,10   ;<--- Vol 1
   Color vol2_1,vol2_2,vol2_3 : Rect 35,100,20,20   ;<--- Vol 2
   Color vol3_1,vol3_2,vol3_3 : Rect 60,90,20,30    ;<--- Vol 3
   Color vol4_1,vol4_2,vol4_3 : Rect 85,80,20,40    ;<--- Vol 4
   Color vol5_1,vol5_2,vol5_3 : Rect 110,70,20,50   ;<--- Vol 5    

   Color 200,200,200

   Text 10,160,"1= "+Volis(0,0)+" | 2= "+Volis(1,0)+" | 3= "+Volis(2,0)+" | 4= "+Volis(3,0)+" | 5= "+Volis(4,0)

   Flip
Wend
;===Main-Loop===
End

Data 1,10,30,110,120,1,35,55,100,120,1,60,80,90,120,1,85,105,80,120,1,110,130,70,120

Neue Antwort erstellen


Übersicht BlitzBasic Allgemein

Gehe zu:

Powered by phpBB © 2001 - 2006, phpBB Group