On 16 May 2013 10:32, Henrik Johansen <henrik.s.johan...@veloxit.no> wrote: > > On May 15, 2013, at 10:34 PM, Eric Clack wrote: > >> Hi Stephane and Jannik, >> Well I don't hate the code (yet ;-) So perhaps I'll have a play with it a >> bit more and see if I can get something that works well, and fits with plans >> for Pharo3.0. >> >> Cheers, >> -Eric. > > Would it be possible to translate it to something like > alias spaceHandler > When space pressed [ > set t1 true] > > When flag clicked [ > set t1 false > install spaceHandler > Loop forever [ > move 5 steps > turn 5 degrees > if t1 [ > Stamp the sprite on the screen > set t1 false > ] > ] > uninstall spaceHandler > ] > > In general, it should be possible to rewrite polling code to event-driven > with some use of temporaries. > +1
you can simply turn polling into non-polling by recording the events (as they come i.e. key-down , then key-up) in some "keyboard map" then your test "if space down" is actually asking keyboard map whether space key is held down or not, and you don't need polling event sensor. For "key pressed" events the story is a bit more complicated, because there's a lot of mess how to translate "key-down /up" pair of physical events (separated by time) into one or series of synthesized "key pressed" events. Operating systems handling them differently, VM (hardcoded) code tries to unify this but IMO is only makes things worse, because it introducing common "worst" denominator. >From VM side, i would really leave only raw event handling (e.g. physical key down/up events) and let image side decide how to synthesize "key pressed" events. However, with devices like touchpads things even worse, because they actually generating only key press events (while actually user still touching screen and then releases after some time, so it is still key down/up physically). (maybe implementing own virtual keyboard in image would be a good solution to that problem) > Cheers, > Henry -- Best regards, Igor Stasenko.