subpixel
Re: my first videogame
Reply #5 - Dec 27th , 2009, 2:57am
Hey atreides, stay calm and think about it some more. The mention of "mousepressed()" was clearly a mistake, since there were no examples of mousepressed before that. Now... you should understand this frameRate business. A normal PAL TV signal is only 25FPS (actually 50 "fields", which are half-frames, per second). 60FPS is twice the speed of an NTSC display. When you use "frameRate(1000)" you're asking Processing to execute your draw() method up to 1000 times per second, if it is able to. It is probably not going to finish what it is doing in less than 1 millisecond, so the actual frame rate is probably a lot less, maybe around 100FPS for something simple. The problem you may be having is that your keyPressed() method is only being called each time a key is "pressed", and if you are holding down a key on your keyboard, the number and rate of "presses" is going to be determined by your key repeat speed (as managed by your operating system preferences at the least). When you hold down, say, "m" in the Processing editor, how quickly do the repeats come? Probably the first "m" appears right away, followed by a short delay then a succession of "m" characters at a fixed rate, and that rate is possibly not very fast. You will notice this same behaviour using the cursor keys - if you want to go up lots of lines, when you hold the up arrow, at first it moves only one line then there is a short pause before it keeps going up. The exact same thing is happening in your game. So, the solution is not to count how many times the key is "pressed" (including key repeat pressings), but to remember whether the key was pressed down and since then not released. That is the idea in antiplastik's example with "boolean keyN". I suggest you use that, with more boolean variables to keep track of other keys you are interested in. -spxl