[Newbies] Stepping of ImageMorph

Jerome Peace peace_the_dreamer at yahoo.com
Sat Jan 16 19:21:41 UTC 2010



--- On Wed, 1/13/10, Hans Gruber <rukin at web.de> wrote:

> From: Hans Gruber <rukin at web.de>
> Subject: [Newbies] Stepping of ImageMorph
> To: beginners at lists.squeakfoundation.org
> Date: Wednesday, January 13, 2010, 10:11 PM
> Hi Guys!
>
>An new question von my side again, because I'm quite new in working with Squeak.
>
>I wanted to animate an ImageMorph in my project. Therefore I figured out to overwrite the Morphs step method and set the stepTime. But that was not I was really looking for.

Have you looked at AnimatedImageMorph? To see how it does it?

>I want to achieve that the ImageMorph switches between several images regarding to the current key which pressed (key event handling is already implemented in my project).

You may wish to have an owner morph that receives keystrokes and switches between several animated submorphs. 

The best way to program squeak is to think LAZY.

>Is there a possibility to start and stop stepping via keystrokes? The next problem would be how to dispatch the different kinds of images changes concerning the current button event.

The step method could call 
self stopStepping
I often use this to create one shot steps.

The part that listens to keystroke could store the keystroke and call startStepping.

Stepping could analyse the keystroke do what is needed and stopStepping after a certain number of steps (you would keep count).

There is also a message called wantsSteps that is queried by the system.
It is also useful to write this method for the morph so that it does not receive steps when it does not want them. 

Even after you request stopStepping if you pickup and drop the morph the world will start stepping it again. The only way I've found to prevent this is to have wantsteps to answer false when I really don't want them.

What I did with one morph was to have it recolor itself during its step then stop stepping. When wantsSteps returns true this morph would recolor each time it was dropped .

Assuming you stored the keyStroke in lastKey you would write wantsSteps as
wantsSteps
^ lastKey = onKey .

or something like that.


Yours in curiosity and service, --Jerome Peace


      


More information about the Beginners mailing list