Page 1 of 1
KeyBoardPushed don't autorepeat.
Posted: Tue Dec 02, 2008 7:21 pm
by Comtois
KeyBoardPushed doesn't work correctly. I must release the key.
is it SDL ? or something wrong ?
is there a workaround ?
Code: Select all
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"Map")
Repeat
ClearScreen(0)
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
ToucheBas + 1
ElseIf KeyboardReleased(#PB_Key_Up)
ToucheHaut + 1
EndIf
EndIf
StartDrawing(ScreenOutput())
DrawText(0,0,"Touche haut " + Str(ToucheHaut))
DrawText(0,20,"Touche bas " + Str(ToucheBas))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Posted: Tue Dec 02, 2008 11:48 pm
by Comtois
WorkAround using a variable. Now it work like under windows.
Code: Select all
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"Map")
Repeat
ClearScreen(0)
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Down)
Key_Down_Pushed=#True
EndIf
If KeyboardReleased(#PB_Key_Down)
Key_Down_Pushed=#False
EndIf
EndIf
If Key_Down_Pushed
ToucheBas + 1
EndIf
StartDrawing(ScreenOutput())
DrawText(0,20,"Touche bas " + Str(ToucheBas))
StopDrawing()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Posted: Wed Dec 03, 2008 12:07 am
by Comtois
this code work fine with windows, is there a way to make smooth (fluid) scrolling under linux ?
Code: Select all
InitSprite()
InitKeyboard()
OpenScreen(1024,768,32,"Map")
Enumeration
#Herbe
#Eau
#Bord
EndEnumeration
Structure S_Box
x.i
y.i
w.i
h.i
EndStructure
Structure POINT
x.i
y.i
EndStructure
#Tx=440
#Ty=440
#Taille=32
CreateSprite(#Bord,#Taille,#Taille)
CreateSprite(#Herbe,#Taille,#Taille)
CreateSprite(#Eau,#Taille,#Taille)
Declare DessineSprite(Sprite, Couleur)
Declare RandomMap()
Declare AfficheMap()
Declare AfficheBox()
Global Offset.POINT
Global ScreenBox.S_Box
ScreenBox\x=120
ScreenBox\y=100
ScreenBox\w=500
ScreenBox\h=300
DessineSprite(#Bord, $0000FF)
DessineSprite(#Herbe, $00FF00)
DessineSprite(#Eau, $FF0000)
Global Dim Map(#Tx,#Ty)
RandomMap()
Repeat
ClearScreen(0)
If ExamineKeyboard()
If KeyboardPushed(#PB_Key_Right)
Key_Right = #True
EndIf
If KeyboardReleased(#PB_Key_Right)
Key_Right = #False
EndIf
If KeyboardPushed(#PB_Key_Left)
Key_Left = #True
EndIf
If KeyboardReleased(#PB_Key_Left)
Key_Left = #False
EndIf
If KeyboardPushed(#PB_Key_Up)
Key_Up = #True
EndIf
If KeyboardReleased(#PB_Key_Up)
Key_Up = #False
EndIf
If KeyboardPushed(#PB_Key_Down)
Key_Down = #True
EndIf
If KeyboardReleased(#PB_Key_Down)
Key_down = #False
EndIf
EndIf
If Key_Right And Offset\x<(#Tx+1)*#Taille-ScreenBox\w
Offset\x + 1
ElseIf Key_Left And Offset\x>0
Offset\x - 1
EndIf
If Key_Down And Offset\y<(#Ty+1)*#Taille-ScreenBox\h
Offset\y + 1
ElseIf Key_Up And Offset\y>0
Offset\y - 1
EndIf
AfficheMap()
AfficheBox()
FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
Procedure DessineSprite(Sprite, Couleur)
If StartDrawing(SpriteOutput(Sprite))
Box(0,0,SpriteWidth(Sprite),SpriteHeight(Sprite),Couleur)
StopDrawing()
ProcedureReturn #True
EndIf
EndProcedure
Procedure RandomMap()
For y=0 To #Ty
For x=0 To #Tx
If x=0 Or x=#Tx Or y=0 Or y=#Ty Or x=#Tx/2 Or y=#Ty/2
Map(x,y)=#Bord
Else
Map(x,y)=Random(1)
EndIf
Next x
Next y
EndProcedure
Procedure AfficheBox()
StartDrawing(ScreenOutput())
DrawingMode(#PB_2DDrawing_Outlined)
Box(ScreenBox\x,ScreenBox\y,ScreenBox\w,ScreenBox\h,$FFFFFF)
StopDrawing()
EndProcedure
Procedure AfficheMap()
Define Src.S_Box, Des.S_Box
Src\y=Offset\y%#Taille
Src\h=#Taille-Src\y
Py=ScreenBox\y
y=Offset\y/#Taille
While Py<ScreenBox\y+ScreenBox\h
Px=ScreenBox\x
x=Offset\x/#Taille
Src\x=Offset\x%#Taille
Src\w=#Taille-Src\x
While Px<ScreenBox\x+ScreenBox\w
ClipSprite(Map(x,y),Src\x,Src\y,Src\w,Src\h)
DisplaySprite(Map(x,y),Px,Py)
Px+Src\w
x+1
Src\x=0
Src\w=#Taille
If (Px+Src\w)>(ScreenBox\x+ScreenBox\w)
Src\w=ScreenBox\x+ScreenBox\w-Px
EndIf
Wend
Py+Src\h
y+1
Src\y=0
Src\h=#Taille
If Py+Src\h>ScreenBox\y+ScreenBox\h
Src\h=ScreenBox\y+ScreenBox\h-Py
EndIf
Wend
EndProcedure
[EDIT]
It seem it is not smooth when i press 2 keys (Down and right for example).
Posted: Thu Dec 18, 2008 1:48 am
by GBeebe
You might want to try storing the green box as a sprite and draw with the sprite instead of using 2d image commands.