Skip to content

Instantly share code, notes, and snippets.

@deathbeam
Last active September 23, 2015 12:06
Show Gist options
  • Save deathbeam/89cbae8aba87b43bd1b8 to your computer and use it in GitHub Desktop.
Save deathbeam/89cbae8aba87b43bd1b8 to your computer and use it in GitHub Desktop.
Raxe example
# 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
@deathbeam
Copy link
Author

haxe-logo3

@deathbeam
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment