-
-
Save markknol/9aaaa5e88287fd308cf8 to your computer and use it in GitHub Desktop.
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 urgame; | |
import flambe.Component; | |
import flambe.Entity; | |
import flambe.System; | |
import flambe.asset.AssetPack; | |
import flambe.asset.Manifest; | |
import flambe.display.FillSprite; | |
import flambe.display.ImageSprite; | |
import flambe.animation.AnimatedFloat; | |
import flambe.display.Graphics; | |
import flambe.display.PatternSprite; | |
import flambe.display.Texture; | |
import urgame.Main.CustomPatternSpriteMover; | |
class Main | |
{ | |
private static function main () | |
{ | |
System.init(); | |
var manifest = Manifest.fromAssets("bootstrap"); | |
var loader = System.loadAssetPack(manifest).get(function onSuccess (pack :AssetPack) | |
{ | |
System.root.addChild(new Entity() | |
.add(new FillSprite(0x202020, System.stage.width, System.stage.height))); | |
System.root.addChild(new Entity() | |
.add(new CustomPatternSpriteMover(40.0, 0.0)) | |
.add(new CustomPatternSprite(pack.getTexture("pattern")))); | |
}); | |
} | |
} | |
class CustomPatternSprite extends PatternSprite | |
{ | |
public var left (default, null):AnimatedFloat; | |
public var top (default, null):AnimatedFloat; | |
public function new (texture:Texture, ?width:Float = -1, ?height:Float = -1) | |
{ | |
super(texture, width, height); | |
this.left = new AnimatedFloat(0); | |
this.top = new AnimatedFloat(0); | |
} | |
override public function draw (g:Graphics) | |
{ | |
if (texture != null) | |
{ | |
g.drawPattern(texture, left._ % width._, top._ % height._, width._, height._); | |
} | |
} | |
override public function onUpdate (dt :Float) | |
{ | |
super.onUpdate(dt); | |
this.left.update(dt); | |
this.top.update(dt); | |
} | |
} | |
class CustomPatternSpriteMover extends Component | |
{ | |
public var speedY:Float; | |
public var speedX:Float; | |
public function new(speedX:Float = 0, speedY:Float = 0) | |
{ | |
this.speedY = speedY; | |
this.speedX = speedX; | |
} | |
override public function onUpdate(dt:Float) | |
{ | |
var sprite = owner.get(CustomPatternSprite); | |
sprite.left._ += dt * speedX; | |
sprite.top._ += dt * speedY; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment