Multidirectional Tile Scroller

author:
Geoffrey Mattie
description:
Scroll tiled images in any direction at any speed.
lastupdate:
2015-05-03
compatible:
v2.x
tag:
Scroll, Tile
homepage:
https://gist.github.com/gmattie/7347573
download:
https://gist.github.com/gmattie/7347573/download

Overview

MultidirectionalTileScroller is a Starling framework extension that easily facilitates multidirectional scrolling of a tiled texture.

After instantiating the object with a width, height and texture, scrolling can be achieved simply by supplying speed and angle arguments prior to or during a play() method call.

//Instantiate the object with a width, height and texture (and optional texture scaling)
m_Background = new MultidirectionalTileScroller(
                                               stage.stageWidth,
                                               stage.stageHeight,
                                               m_Texture,
                                               1.0,
                                               1.0
                                               );
//Add it to the stage
addChild(m_Background);
 
//Assign speed and angle values prior to calling play().
m_Background.speed = 2;
m_Background.angle = -42;
m_Background.play();
 
//Optionally pass new speed and angle arguments to the Start function.
m_Background.start(0.25, 180);
 
//Stop Scrolling by calling stop().
m_Background.stop();
 
//To maintain the previously set speed and angle properties, simply call play() again.
m_Background.play();

Public Properties

  • angle:Number
  • isAnimating:Boolean [read only]
  • speed:Number

Public Methods

  • MultidirectionalTileScroller(width:uint, height:uint, texture:Texture, textureScaleX:Number = 1.0, textureScaleY:Number = 1.0)
  • dispose():void
  • play(speed:Number = NaN, angle:Number = NaN):void
  • setSize(width:uint, height:uint):void
  • setTexture(texture:Texture, textureScaleX:Number = 1.0, textureScaleY:Number = 1.0):void
  • stop():void

Notes

  • The maximum speed (pixels per frame) is capped at the texture's smallest width or height
  • Angle values are in degrees (not radians)
  • Default speed value is 0.0
  • Default angle value is 0.0

Changelog

  • 2015/05/03: Replaced legacy QuadBatch with MeshBatch to support Starling v2.x.
  • 2013/12/07: Added public setTexture(~) and setSize(~) functions.
  • 2013/11/09: Changed m_Canvas from a Sprite to a QuadBatch.
  • 2013/11/08: Added public dispose() function.
  • 2013/11/07: First public version.

Source Code

%gist(7347573)%

User Comments

Feel free to edit this part of the page!

  extensions/multidirectional_tile_scroller.txt · Last modified: 2021/01/07 16:13 by daniel
 
Powered by DokuWiki