One thing that could make games possibly a lot more fun would be sensing keydown/keyup as opposed to just keypress. With keypress the repeat delay and repeat rate of the keyboard (system preferences dependent) affects how things move and makes things a bit jerky. If you could sense keydown/keyup, on keydown you could set a variable "speed" to 5 and have it update smoothly, and on keyup you could reset "speed" to 0. This way people could have the same smooth experience regardless of what their keyboard settings are.
Offline
Everything you need to do what you're after exists. I don't think that Scratch "pays attention" to delays or repeats, just "pressed or not". Try this demo that shows how to make a variable (Throttle for the Airplane) respond smoothly:
http://scratch.mit.edu/projects/EdnaC/34922
If this is doing what you want, download for a look. Feel free to remix into a full-fledged game. This demo is a stripped-down verson of Stealthfighter.
Last edited by EdnaC (2007-09-09 08:46:21)
Offline
On my Mac, the
[blocks]
<when[ space ]key pressed>
[/blocks]
block certainly is sensitive to the repeat delay and rate of the key.
but
[blocks]
<forever if><key[ a ]pressed?>
[/blocks]
is not sensitive to repeats.
Offline
You're right. It looks like the "When (key) Pressed" hat responds to both the delay and the repeat. The <key pressed?> operator seems to not respond to the delay. I don't know how to tell if the repeat is happening or the Scratch code is just executing over and over when the key is held.
In either case, I haven't run into this being an issue.
Vaz,
Have you found a solution to the issue you were having? If not; Can you post a link to an example?
-Mr Ed
Last edited by EdnaC (2007-09-09 08:41:02)
Offline
Ok. I wasn't aware that the"key pressed?" worked that way (I assumed it worked the same as kevin's first example, which is what I was using). The "when ? key pressed" block definitely depends on the delay/repeat rate of the keyboard, you can tell in games where the sprite you're controlling will jerk forward when you hit the key, wait a second and then start moving (somewhat) more smoothly.
I think "key pressed?" will do everything I was looking for. Thanks.
Oh. I put "mouseup" in the title but didn't mention anything about it. Sometimes it could be neat to trigger things on mouseup events. I haven't tried this at all so there could very well be a way to do this, even something similar to the keypress situation, I just noticed the "mouse down" block and thought about mouseup.
Last edited by vaz (2007-09-09 10:27:11)
Offline
mouse down and mouse up are not events, but states, so not(mouse down?) should work for you. The "when sprite clicked" *is* an event, like "when key pressed" and actually doesn't happen until the mouse is released.
Offline
More generally, if I want to make a 2-player (on same keyboard) game with real-time action (not a turn-based game), what is the best way to ensure that a player cannot "cheat" by simply holding down a key forever?
Offline