Last active
December 19, 2015 05:39
-
-
Save seaders/5905342 to your computer and use it in GitHub Desktop.
Simple bit to allow you to have a background skin which has a constantly centered starling Image in it.
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
/* | |
Copyright 2013 Seadna Long. All Rights Reserved. | |
This program is free software. You can redistribute and/or modify it in | |
any way. | |
*/ | |
package com.bluemanimposter.custom.starling.display | |
{ | |
import starling.display.DisplayObjectContainer; | |
import starling.display.Image; | |
public class ImageCenterSkin extends DisplayObjectContainer | |
{ | |
/** | |
* Constructor. | |
*/ | |
public function ImageCenterSkin(img:Image, horizAlign:Boolean=true, vertAlign:Boolean=true) | |
{ | |
this._image = img; | |
this.addChild(this._image); | |
this._horizAlign = horizAlign; | |
this._vertAlign = vertAlign; | |
} | |
/** | |
* @private | |
*/ | |
private var _width:Number; | |
/** | |
* @private | |
*/ | |
private var _height:Number; | |
/** | |
* @private | |
*/ | |
private var _image:Image; | |
/** | |
* @private | |
*/ | |
private var _vertAlign:Boolean; | |
/** | |
* @private | |
*/ | |
private var _horizAlign:Boolean; | |
/** | |
* Overriding width setter and centrally align it, if need be. | |
*/ | |
override public function set width(value:Number):void | |
{ | |
this._width = value; | |
if(this._horizAlign) | |
{ | |
this._image.x = (value / 2) - (this._image.width / 2); | |
} | |
} | |
override public function get width():Number | |
{ | |
return this._width; | |
} | |
/** | |
* Overriding height setter and centrally align it, if need be. | |
*/ | |
override public function set height(value:Number):void | |
{ | |
this._height = value; | |
if(this._vertAlign) | |
{ | |
this._image.y = (value / 2) - (this._image.height / 2); | |
} | |
} | |
override public function get height():Number | |
{ | |
return this._height; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment