4

短信版本 2.1.2.3592

当应用程序已被浏览器调整大小时(在 TW3CustomGameApplication 中),我如何进行重绘或调用 PaintView 方法?

我正在使用 GameView.Width 和 GameView.Height 属性来确定我的应用程序中很多东西的尺寸。当应用程序大小发生变化时,我需要重绘或重绘

看起来没有要覆盖的 Resize 事件。

问题

1.) 如何捕获调整大小事件?

2.) 我如何重绘?

4

1 回答 1

4

I'm not very familiar with the internals of the TW3CustomGameApplication class, but at any time it should be possible to add a dedicated event handler for every event that occurs on the JavaScript side.

For example you can hook the resize event for underlying canvas element with code like this:

GameView.Context.Handle.addEventListener('resize', @ResizeEvent);

with ResizeEvent looking like

procedure TYourClass.ResizeEvent(Event: JEvent);
begin
  // handle resizing
end;

Alternatively you can also hook the global window resizing with this code:

Window.addEventListener('resize', @ResizeEvent);

This can be useful if you have a fixed size canvas and want to adjust it according to the window size manually.

Since this hooks the underlying W3C low level APIs you might need to add the units W3C.HTML5 and W3C.DOM.

The advantage of using the underlying low level APIs is the good documentation / specification by the W3C and others, like:

The downside of this approach is that you need to do everything yourself (reinvent the wheel).

For small size applications or a RAD workflow I would definitely suggest to stick with the code that TW3CustomGameApplication offers, but for a big project looking deeper makes probably more sense.

于 2016-01-06T11:18:06.733 回答