# Template for a 2D gamnit game
module template is
+ example
app_name "gamnit template"
app_namespace "org.gamnit.template"
app_version(0, 1, git_revision)
android_api_target 10
end
-import gamnit::flat # For `Texture, Sprite`, etc.
-import gamnit::keys # For `pressed_keys`
-import app::audio # For `Sound`
+import gamnit::flat # The 2D API, use `gamnit::depth` for 3D
redef class App
- # Texture, loaded automatically at `on_create`
+ # Texture, loaded in `create_scene`
var texture = new Texture("fighter.png")
# Sound effect, lazy loaded at first use
# Sprite, must be loaded in or after `on_create`
var sprite = new Sprite(texture, new Point3d[Float](0.0, 0.0, 0.0)) is lazy
- redef fun on_create
+ redef fun create_scene
do
super
# Scale the ship so it is approximately 5 world units wide.
sprite.scale = 5.0 / texture.width
- # Move the camera to show 10 world units on the Y axis at Z = 0.
+ # Move the camera to show 20 world units on the Y axis at Z = 0.
# The `sprite` should take approximately 1/4 of the height of the screen.
world_camera.reset_height 20.0
# cause glitches on mobiles devices with small depth buffer.
world_camera.near = 1.0
- # Make the background blue and opaque.
- glClearColor(0.0, 0.0, 1.0, 1.0)
+ # Make the background sky blue and opaque.
+ glClearColor(0.5, 0.8, 1.0, 1.0)
# If the first command line argument is an integer, add extra sprites.
if args.not_empty and args.first.is_int then
if event isa QuitEvent or
(event isa KeyEvent and event.name == "escape" and event.is_up) then
# When window close button, escape or back key is pressed
- # show the average FPS over the last few seconds.
- print "{current_fps} fps"
+ print "Ran at {current_fps} FPS in the last few seconds"
+
+ print "Performance statistics to detect bottlenecks:"
print sys.perfs
# Quit abruptly