0

i am trying to make aan animation for my game in DrRacket, when i press the left button i want my image to do a running animation (legs open --> legs closed). Is there a way i can delay the image swap? The computer does the swap soo fast that you dont see the swap happening. -->

(define (keyboard-function key)
  (cond ((eq? key 'left) (tekenaar 'mario-next!)
                       ((mario-adt 'move) 'left)
                       (tekenaar 'mario-next!))
      ((eq? key 'right) ((mario-adt 'move) 'right)
                        (tekenaar 'mario-next!))
      (else (void))))

Thanks

KillerZ224
  • 41
  • 2
  • You should decide how fast you want to animate leg movement (e.g.: twice a second), you need to add time and change animation only every 0.5secons or so instead of every frame like you do it now. – Ondrej Dec 08 '17 at 08:21
  • How do I do that in Racket? Is there a procedure "time"? – KillerZ224 Dec 08 '17 at 19:06

1 Answers1

1

You can't really make the computer delay the swap itself. What you can do is delay it yourself.

You could do this by keeping a counter you increment every frame. When that counter reaches a certain number, you swap the images. This way, instead of swapping them every frame, you swap them every x frames.

An easy way to do this is as follows:

(define counter 0)
(set! counter (modulo (+ counter 1) 50))
(if (= counter 0)
    ; start drawing the other image)
Aaron L
  • 96
  • 1
  • 4