A wx panel that shows a world: the canvas drawn from the sheet around the focus, the hud beside or below it if the game sends one, the keys and the pointer as input, the sound through the speaker.
view = Cauldron2D.Wx.View.new(parent, keymap: keymap, steering: [:left, :right], on_over: fn over -> ... end)
Cauldron2D.Wx.View.join(view, {:socket, url: url, token: token, topic: "world:main", params: %{}})
Cauldron2D.Wx.View.join(view, {:local, game: MyGame.Web, world: pid, name: "alice", props: %{}})
Cauldron2D.Wx.View.leave(view)Options
:keymap— wx key codes and{:mouse, button}to actions, asCauldron2D.Wx.Input.new/2takes:steering— the actions the pointer also drives:size— the least the canvas is, in pixels, default{800, 600}; it grows with the window:scale— pixels per sheet pixel, default1:hud— where the hud rows go::right(default),:bottom, or:nonefor no hud panel:hud_size— the hud panel's width (right) or height (bottom) in pixels, default300:hud_colours—%{background: rgb, text: rgb}for the hud panel, default a dark panel with light text:font— the hud's font in points, default12:on_over— called with the outcome when the round is over for this player; the game draws what it likes then, the canvas draws nothing of its own:on_closed— called with the reason when the link ends:on_refused— called with the reason when the join is refused:on_key— called with the wx key code of a key that went down and means no action:sound—falsefor no sound:input_every— milliseconds between input messages, default100:pointer— whether the pointer aims, defaulttrue;pointer/2changes it later:zoom—truelets the player zoom:+/=in,-out,0back to the game's scale, the wheel either way, from a tile of 2 pixels (or the whole map in view, whichever is larger) to 64;zoom/2sets a tile size from outside. Defaultfalse. A whole map that fits in 4096 pixels a side is drawn from one bitmap of it at the current size, so zooming out to see all of it costs nothing a frame; the sheet at each size is kept for the view's life, its bitmaps in one table the painter reads, so a zoom never takes a sheet from under a paint in progress. Watching — joined withspectateamong the link's props or params — the view can also be panned: the arrows and a drag with the left button move it, the wheel zooms about the pointer,0recentres it as well, and a frame whose subject is not the one the pan was taken on drops the pan:on_stats— called once a second with%{frames: n, draws: n}, the frames received and the times the canvas was painted in that second:show_stats— draw those numbers in the canvas's top left corner, defaultfalse;show_stats/2changes it later
The canvas is cleared to the sheet's void colour. Input goes to the link on every
change and every :input_every ms.
Summary
Functions
Give the canvas the keyboard.
Join a world through a link: {:socket, opts} or {:local, opts}, the options of the link module less :owner.
Read keys by another keymap from now on, as new/2's :keymap; what was held is let go.
Leave the world.
The effects and music levels, 0.0 to 1.0.
The arena panel under parent.
Pause or resume a world of the player's own, through the link.
Whether the pointer aims from now on.
Whether the frames and draws a second are drawn on the canvas from now on.
The panel's wx window.
Draw tiles pixels wide from now on, within the zoom's limits.
Functions
@spec focus(term()) :: :ok
Give the canvas the keyboard.
Join a world through a link: {:socket, opts} or {:local, opts}, the options of the link module less :owner.
Read keys by another keymap from now on, as new/2's :keymap; what was held is let go.
@spec leave(term()) :: :ok
Leave the world.
The effects and music levels, 0.0 to 1.0.
The arena panel under parent.
@spec pause(term()) :: :ok
Pause or resume a world of the player's own, through the link.
Whether the pointer aims from now on.
Whether the frames and draws a second are drawn on the canvas from now on.
The panel's wx window.
@spec zoom(term(), pos_integer()) :: :ok
Draw tiles pixels wide from now on, within the zoom's limits.