Window Update Event

Can you assign something to Window.OnUpdate := @WindowUpdate to something like Window.OnUpdate := @SOMETHING to stop the Update Event ?

If you want to stop the Update event, you should use Window.AutoRedisplay := false;. After that you’ll need to call Window.Invalidate; to manually update the window each time.
(UPD) Window.OnUpdate is just a call-back that is called every time the window gets updated.

1 Like

To stop receiving OnUpdate, set it to nil, like this: Window.OnUpdate := nil.

I think Eugene confused OnUpdate with OnRender:) Some clarifications:

  • OnUpdate is called continuously on the window, whether it’s redrawn or not, and regardless of the AutoRedisplay value.

  • If the window is redrawn all the time, then OnRender and OnUpdate will be called with the same frequency, but it does not make these events “tied” to each other. You should never depend that they have exactly the same frequency, even if it’s true in some cases.

  • And note that setting AutoRedisplay doesn’t prevent automatic OnRender . OnRender will still happen when the GUI backend (e.g. GTK or WinAPI) says that the window was obscured and now it’s not. And on some platforms (Android) AutoRedisplay is ignored, system requires to redraw window all the time. And internally the engine calls Invalidate at various points. In general, you must always be ready to render your current application state, you cannot get away with it and control it manually.

2 Likes

Thanks. And can I use the nil value for other Events? Like Window.OnPress := nil to temporary suspend the event ?

Oh…? I should double-check this, but I most certainly had to create “workarounds” for this issue in Swappy Jigsaw (it has AutoRedisplay = false, and therefore there was no way to get timed events in Linux otherwise than temporarily switching AutoRedisplay to true; thou that was 2 months ago, maybe I’ve missed something).
Thanks! I’ll check it :slight_smile:

Yes. You can even easily assign different events in different situations. E.g. You can assign Window.OnPress := @PressMenu and then when the game starts you can replace it with Window.OnPress := @GamePress and return previous value when the player returns to menu.

2 Likes

One more question. Can you make multiple OnTimer events with different time intervals?

For multiple timers, create instances of TCastleTimer. Each TCastleTimer instance has it’s own IntervalSeconds and OnTimer. The example in engine sources examples/2d_standard_ui/timer_test/ ( https://github.com/castle-engine/castle-engine/blob/master/examples/2d_standard_ui/timer_test/timer_test.lpr ) shows this.

2 Likes