CanvasActor
A CanvasActor is a special kind of Actor that can scroll its content around as well as dock its content to its edges, CanvasActor’s are designed for creating user interfaces. CanvasActor is derived from Actor thus inherits all of its properties, methods and so on. Not that any actors that are docked and are added to a CanvasActor will be docked against the edges of the CanvasActor instead of the Scene.
Public properties
- scroll_pos_x – Canvas scroll X position
- scroll_pos_y – Canvas scroll Y position
- scroll_vx – Canvas scroll X velocity
- scroll_vy – Canvas scroll Y velocity
- scroll_range – Scrollable range of canvas (left, top, width, height)
Internal properties
- prev_scroll_pos_x – Previous canvas scroll X position
- prev_scroll_pos_y – Previous canvas scroll Y position
Methods
CanvasActor() – Creates an instance of a CanvasActor
onTouchMoveBase(touch_pos) – Base touch movement handler (called by the system) which provides content scrolling functionality
- The touched position
update(dt) – Updates the actor, this method can be overriden by derived actors. This is a customised update handler which provides content scrolling functionality
- dt – The amount of time that has passed since this actor was last updated
scrollRangeCheck() – A utility method that is used to keep the content from scrolling out of range
updateLayout() – Called to update the layout of the content, should be called if any of the actors that make up the content are changed (for example if any of the content actors are undocked)
Examples
Example showing how to create a canvas actor that can scroll its content
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
var canvas_actor = new CanvasActor(); canvas_actor.w = 200; canvas_actor.h = 200; canvas_actor.x = 100; canvas_actor.y = 100; canvas_actor.bitmap = scene.findResource("my_bitmap", "bitmap");; canvas_actor.touchable = true; // Can receive touch events canvas_actor.clip_children = true; // Clips children against extents canvas_actor.scroll_range = [-100,-100,200,200]; // Set scroll range of content scene.addActor(canvas_actor); var child_actor = new Actor(); child_actor.w = 50; child_actor.h = 50; child_actor.bitmap = scene.findResource("my_bitmap", "bitmap");; canvas_actor.addActor(child_actor); // Add actor as child of canvas actor |
283 total views, 1 views today