The game is controlled via keyDown on MacOS. The arrow keys control movement. The problem I’m having is that when I press and hold the key, the game stops working until I release the key. How can I make it so that there is an internal interval in the keydown event, so that other processes continue to run, even with keydown pressed?
Select Case key.Asc
Case 30
c_game.fly.Move("UP", c_game)
Case 29
c_game.fly.Move("RIGHT", c_game)
Case 31
c_game.fly.Move("DOWN", c_game)
Case 28
c_game.fly.Move("LEFT", c_game)
End Select
If myCanvas<>Nil Then
myCanvas.Refresh
End If
Return True
i tried but it’s not working. i’ll give more details:
wdwGame
— event
— — keydown
// game starts here, after first keydown
// will be changed in the future
GameTimer.Mode = Timer.ModeMultiple
Select Case key.Asc
Case 30
c_game.mm.Move("UP", c_game)
Case 29
c_game.mm.Move("RIGHT", c_game)
Case 31
c_game.mm.Move("DOWN", c_game)
Case 28
c_game.mm.Move("LEFT", c_game)
End Select
If myCanvas<>Nil Then
myCanvas.Refresh
End If
Return True
controls
— gametimer
— — action
// apago o caminho para que o algoritmo crie um novo!!!
c_queue.items.RemoveAll
Var algorithm As myAlgo = New myAlgo2025
algorithm.MovePetGame(c_game)
myCanvas.Refresh
— myCanvas
— — paint
If levelLoaded Then
// limpo o fundo
g.DrawingColor = gameBackgroudColor
g.FillRectangle(0, 0, g.Width, g.Height)
// … etc, etc …
End If
generally try to follow what your game/events do with debug output.
Function KeyDown(key As String) Handles KeyDown as Boolean
System.DebugLog CurrentMethodName
Select Case key.Asc
Case 30
System.DebugLog("UP")
Case 29
System.DebugLog("RIGHT")
Case 31
System.DebugLog("DOWN")
Case 28
System.DebugLog("LEFT")
End Select
End Function
your canvas paint event could look like this.
means this game class have methods with g as graphics argument.
Sub Paint(g As Graphics, areas() As Rect) Handles Paint
Game.PaintBackground(g)
Game.PaintFigures(g)
End Sub
yes as i saw your example code i asked myself why are you setting the timer mode there.
its still the wrong place.
try using a enumeration for your game/pet/player status or a flag as condition.
games usually have minimum 2 running timers, one for the update and one for the drawing.
as example physics run 1000 times per second and the drawing 60 fps. (parallel)