Nine Slice
package;
import gecko.Assets;
import gecko.Gecko;
import gecko.math.Random;
import gecko.systems.draw.DrawSystem;
import gecko.components.draw.NineSliceComponent;
class Game {
var _spritesToLoad = ["images/kenney/grey_button08.png", "images/kenney/green_panel.png"];
public function new(){
Gecko.currentScene.addSystem(DrawSystem.create());
Assets.load(_spritesToLoad, _onLoadAssets).start();
}
private function _createNineSlice(x:Float, y:Float, width:Float, height:Float) {
var entity = Gecko.currentScene.createEntity();
entity.transform.position.set(x, y);
entity.addComponent(NineSliceComponent.create(_getRandomSprite(), width, height));
entity.transform.anchor.set(0,0);
}
private function _onLoadAssets() {
_createNineSlice(50, 50, 200, 100);
_createNineSlice(50, 170, 100, 400);
_createNineSlice(170, 170, 400, 400);
_createNineSlice(270, 50, 60, 100);
_createNineSlice(350, 50, 40, 40);
_createNineSlice(350, 110, 40, 40);
_createNineSlice(410, 50, 120, 100);
_createNineSlice(550, 50, 200, 40);
_createNineSlice(550, 110, 200, 40);
_createNineSlice(590, 170, 160, 80);
_createNineSlice(590, 270, 60, 300);
_createNineSlice(670, 270, 80, 300);
}
private function _getRandomSprite() : String {
return _spritesToLoad[Random.getUpTo(_spritesToLoad.length-1)];
}
}
Source Code