I’m having some trouble with “timers” to make some things goes on correct order… but this is one of the problem that I’m trying to figure it out by myself (yet)
The actual problem is that the "arrow key"on my MacBook M1, moves the object on game faster than on my iMac 2013… and different on windows… linux, etc. every OS (and machines) I have different "speeds"of the object.
The first think I noticed and fixed is the “repeat keyboard delay”… but now the problem is how to “setup” the same speed independent of OS, or processor speed…
Hello, I’ve always done it this way: I specify the distance the objects can move in 1000 milliseconds. The method queries how long ago it was last called, and then converts the value. If the movespeed variable for a player is 5 and the method was last called 16 milliseconds ago, the player can only move 0.08 units. The time of the last call to the method must, of course, be saved. Regards, Norbert
the game is running, but i know i can make it much robust before publish. that’s what i’m looking for. i know what i need / want to do, but i’m lost on how to implement this.
i’m trying to figure out how to use the window keydown + canvas paint + timer, to control some sequences. and the speed of some objects.
I didn’t realize how to integrate those 3…
some examples:
when the mouse dies, i want to make a vanish effect on it, then it vanishes, then the vanishes appear on another place, than the mouse reborn…
change the speed of mouse dynamically, on certain conditions, during the game…
Thats one approach.
Another is to have the timer fire as often as it needs to, and in the event check what is moving, and move it.
Or update an animation.
Each object needs to be aware of it’s own state, and react when given an ‘update yourself’ message by the timer
You definitely have to use the keyboard.asynch. For games I would keep the drawing (paint event) as simple as possible. Do the transitions in a datatype e.g. an array or class. Let’s say you have a class Mouse. Properties of the Mouse can be a Picture, X and Y coordinates en a vector, that is what the speed per tick is over the x and y axis. Have a PlayTimer that looks into the user input and updates the properties accordingly. Then refresh the Canvas so the Paint event fires and draws the object or whatever with the changed coordinate and vector. Speed is thus controlled by the timer interval. With more mice have an array of type Mouse and loop through that array every timer tick and change the properties. Let the Paint event loop through that array and draw the different mice on the canvas.
Hi Alexandre, that is because of Keydown. You’d better use KeyBoard.Async and handle every keydown in a timer loop or put it into an event queue and handle accordingly.