Last active
February 29, 2020 09:35
-
-
Save PrimaryFeather/2310972 to your computer and use it in GitHub Desktop.
This Starling extension class displays a texture, trimmed to its left side, depending on a ratio. This can be used to create a progress bar or a rest-time display.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package starling.extensions | |
{ | |
import starling.display.Image; | |
import starling.display.Sprite; | |
import starling.textures.Texture; | |
import starling.utils.MathUtil; | |
public class Gauge extends Sprite | |
{ | |
private var _image:Image; | |
private var _ratio:Number; | |
public function Gauge(texture:Texture) | |
{ | |
_ratio = 1.0; | |
_image = new Image(texture); | |
addChild(_image); | |
} | |
private function update():void | |
{ | |
_image.scaleX = _ratio; | |
_image.setTexCoords(1, _ratio, 0); | |
_image.setTexCoords(3, _ratio, 1); | |
} | |
public function get ratio():Number { return _ratio; } | |
public function set ratio(value:Number):void | |
{ | |
_ratio = value > 1 ? 1 : (value < 0 ? 0 : value); | |
update(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@camelic —
An example with images would be useful but it's not that difficult to figure it out.
So a sample background would be like this one — http://cl.ly/image/222I1z2K092W
and the inner part which would be — http://cl.ly/image/1x002242273b
Hope this helps.