Closed sc0ttj closed 3 years ago
https://github.com/sc0ttj/component/pull/52
This PR includes a lot of the above, except sprites, tiling/maps, and stuff that requires interactivity.
Interactivity (like click, hover, drag & drop, gamepads, keyboard) can't easily be done with the canvas API alone - it doesn't keep a reference to anything it draws.
To solve this, each thing you draw (rectangle, star, image) needs an JS Object created as a reference to it:
These reference objects usually have an update()
method, for updating its properties, and a render()
method for rendering to canvas once the props have been updated.
...I've yet to decide how I want to implement this, and whether or not it should go into a separate add-on specifically for defining "game objects", or similar - Ctx
would automatically use it, if it's available.
Nothing too grand is needed - Component
already has a setState/render cycle, and nicely separated states and views - the references to the things drawn/rendered, and the re-rendering of them, can (probably) be hooked into the existing component lifecycle, using just states and views.
Done .. See PR #52
This add-on may need re-visiting to enable adding interactivity, easy sprites, tiling/tiled "maps" - anything past that would be out of scope for this add-on, which is basically for drawing/rendering stuff only.
An add-on which extends the canvas 2d context, to provide the following features:
click
,release
,drag
andmouseover
,mouseout
eventstoImage()
method, enable adding filters)toVideo()
method, which saves the canvas animation as a videotile
method, for more eaily creating tiled backgrounds/environmentssprite
method, for more easily creating animatable sprites (using spritesheets)See these libraries for ideas:
ctx.clear()
methodmouseover
,mouseout
events/methods, etc