Last active
September 23, 2015 12:06
-
-
Save deathbeam/89cbae8aba87b43bd1b8 to your computer and use it in GitHub Desktop.
Raxe example
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
# Require some other modules | |
require "openfl/display/Sprite" | |
require "openfl/events/Event" | |
require "openfl/Lib" | |
# Set type of this module to class and extend it by OpenFL sprite | |
module class extends Sprite | |
# Module variables | |
def static appname = "My Application" | |
def static instance = new Main() | |
def static instance() | |
return instance | |
end | |
# Instance variables | |
def cacheTime : Float | |
def speed : Float | |
def sprite : Sprite | |
# Create a new instance of class Main | |
# It is just entry point for OpenFL | |
def new() | |
super() | |
puts("This is " + appname) | |
# Create our super sprite | |
sprite = new Sprite() | |
sprite.graphics.beginFill(0x24AFC4) | |
sprite.graphics.drawRect(0, 0, 100, 100) | |
sprite.y = 50 | |
addChild(sprite) | |
# Initialize rest of things | |
speed = 0.3 | |
cacheTime = Lib.getTimer() | |
# Event listener magic, hell yeah | |
addEventListener(Event.ENTER_FRAME, def(event) | |
var currentTime = Lib.getTimer () | |
update (currentTime - cacheTime) | |
cacheTime = currentTime | |
end) | |
end | |
# Just main loop. I love them. | |
def update(deltaTime) | |
if (sprite.x + sprite.width >= stage.stageWidth || sprite.x <= 0) | |
speed *= -1 | |
end | |
sprite.x += speed * deltaTime | |
end |
Author
deathbeam
commented
Sep 22, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment