Last active
August 29, 2015 14:18
-
-
Save G4MR/c115f758eee4b2c84c6d to your computer and use it in GitHub Desktop.
Enjoy2d Example
This file contains hidden or 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
include lib | |
# new image object | |
var img : Image | |
# font object (UTF8 support) | |
var myfont = initFont( | |
"UTF8 Test ǽ Ǽ ǻ Ǿ", # Default Text (which can be changed) | |
20, # Font Size | |
"OpenSans.ttf", # Font | |
(0, 0, 255, 255), # RGBA | |
render_type = "utf8", # tells if we're using utf8 or not, might make this defautl | |
text_type = "blendwrap", # enables line wrapping | |
wrap_length = 100 # wrap lines @ 100 pixels | |
) | |
# game object | |
var app = initApp("Example", 800, 600) | |
# Run after the game loop finishes | |
app.after(proc(app: EAppMain) = | |
img.close() | |
) | |
# Run before the game loop happens (load objects) | |
app.before(proc(app: EAppMain) = | |
# load image & set the sprite location (if we wanted to crop) | |
img = loadImage("example.jpg", app.render) | |
img.setSrc(0,0,500,400) | |
# get center of window for a proper x, y position | |
let pos_x = int((app.getWidth() / 2) - (img.getWidth() / 2)) | |
let pos_y = int((app.getheight() / 2) - (img.getheight() / 2)) | |
# position image in the center of the screen | |
img.setXY(pos_x, pos_y) | |
) | |
# first thing to run int he game loop | |
app.events(proc(app: EAppMain) = | |
discard #echo ($app.etype) | |
) | |
# runs before draw in the game loop | |
app.update(proc(app: EAppMain, dt: float) = | |
discard | |
) | |
# runs before the end of the game loop | |
app.draw(proc(app: EAppMain, render: RendererPtr) = | |
myfont.draw(render, 100, 100) | |
img.draw(render) | |
) | |
# set frame limit | |
app.setFps(30) | |
# run application | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment