Hello, I have a problem with world functions. If I don’t touch keypad or mouse it stops when image reaches at the right edge of the scene, but If I click mouse or press a key, it never stops. (define (main ws) (big-bang ws [on-tick tock] [to-draw render] [stop-when gone] ;; This doesn’t work if I press a key or click with mouse !!! [on-mouse mouse-event-handler] [on-key handle-key] ))
How is gone
defined?
it should stop when image mostly disappeared from the scene: (define (gone cw) (= cw (+ BACKGROUND-W 23)))
Try (define (gone cw) (>= cw (+ BACKGROUND-W 23)))
it worked perfect. Thanks.
But If I may ask; why it works? I mean it would be true in either cases, because x position of the image will eventually be equal to that specific number at some point?
Well, as it turned out cw
never did equal (+ BACKGROUND-W 23))
. To check you need a way to see the value of cw
during the run of the program. One way is to change your render
methods to do this:
(overlay (text (number->string cw))
...what you have now in render...)
This way you can follow the value of cw
as the program runs.
Thank you very much, ok I’ll try it.
Ah ok, now I understand why they won’t be equal. Because tick and the image pixels won’t overlap, when I intervene with a key or the mouse. Thanks again.