[Haskell-beginners] firering event in netwire

Ertugrul Söylemez es at ertes.de
Mon Oct 1 13:58:34 CEST 2012


Nathan Hüsken <nathan.huesken at posteo.de> wrote:

> Now I want my state updates frame based, not time based. I am trying
> to update the state based on the NoEvent event (the main look takes
> care that this happens in an constant interval).

With Netwire you can have your own time frame.  For example you can just
call stepWire with a constant dt or you can use the counterSession.


> I have an Event Wire
>
> isKeyPressed code :: EventP SDL.Event"
>
> which produces when the key is pressed and inhibits when it is not
> pressed.
>
> speed = (((pure (-1.0)) . isKeyPressed leftKeyCode) <|> pure 0.0)
>               +
>         (((pure 1.0)  . isKeyPressed rightKeyCode) <|> pure 0.0)

Let me rewrite this to make it slightly more pleasing to the eye:

    speed = ((-1) . isKeyPressed leftKeyCode <|> 0) +
            (1 . isKeyPressed rightKeyCode <|> 0)

> So speed is -1 if the left key is pressed, +1 if the right key is
> pressed and 0 if none or both are pressed.
>
> Now I want to integrate this speed (frame based):
>
> pos = accum (+) . speed

This should be a type error.  Rather:

    pos = accum (+) initialPos . speed


> But this does not do the accumulation every frame, but whenever an
> event happens.

That wire by itself does the accumulation at every frame, so you
probably have an inhibiting wire earlier in the chain.


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121001/16f5973a/attachment.pgp>


More information about the Beginners mailing list