private var fx_explosion_ship = new Sound("sounds/explosion_ship.wav")
private var fx_explosion_asteroids = new Sound("sounds/explosion_asteroids.wav")
- redef fun on_create
+ redef fun create_scene
do
super
import asteronits
redef class App
- redef fun on_create
+ redef fun create_scene
do
super
# var pos: Point3d[Float] = ui_camera.top_left.offset(128.0, -128.0, 0.0)
# var ui_text = new TextSprites(font, pos)
#
-# redef fun on_create
+# redef fun create_scene
# do
# super
#
end
end
- redef fun on_create
+ redef fun create_scene
do
super
initialize_head_tracker
redef class App
- redef fun on_create
+ redef fun create_gamnit
do
super
# 3D model composed of `Mesh` and `Material`, loaded from the assets folder by default
#
-# Instances can be created at any time and must be loaded after or at the end of `on_create`.
+# Instances can be created at any time and must be loaded after or at the end of `create_scene`.
# If loading fails, the model is replaced by `placeholder_model`.
#
# ~~~
private var perf_clock_shadow = new Clock is lazy
- redef fun on_create
+ redef fun create_gamnit
do
super
private var perf_clock_dynamic_resolution = new Clock is lazy
- redef fun on_create
+ redef fun create_scene
do
super
# Bottom right corner
var corner = new Texture("corner.png")
- redef fun on_create
+ redef fun create_scene
do
super
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
# Vertex data for the triangle
var vertex_array: VertexArray is noautoinit
- redef fun on_create
+ redef fun create_scene
do
super
# Second performance clock for smaller operations
private var perf_clock_sprites = new Clock is lazy
- redef fun on_create
+ redef fun create_gamnit
do
super
+ create_flat
+ end
+ # Prepare the flat framework services
+ fun create_flat
+ do
var display = display
assert display != null
redef class App
- # Main `GamnitDisplay` initialized by `on_create`
+ # Main `GamnitDisplay` initialized by `create_gamnit`
var display: nullable GamnitDisplay = null
- redef fun on_create
+ # Hook to setup the OpenGL context: compiling shaders, creating VBO, reloading textures, etc.
+ #
+ # The gamnit services redefine this method to prepare optimizations and more.
+ # Clients may also refine this method to prepare custom OpenGL resources.
+ fun create_gamnit
do
- super
-
var display = new GamnitDisplay
display.setup
self.display = display
print "GL extensions: {glGetString(gl_EXTENSIONS)}"
end
+ # Hook for client programs to setup the scene
+ #
+ # Refine this method to build the game world or the main menu,
+ # creating instances of `Sprite` and `Actor` as needed.
+ #
+ # This method is called only once per execution of the program and it should
+ # be considered as the entry point of most game logic.
+ fun create_scene do end
+
# Core of the frame logic, executed only when the display is visible
#
# This method should be redefined by user modules to customize the behavior of the game.
accept_event gamnit_event
end
end
+
+ redef fun on_create
+ do
+ super
+ create_gamnit
+ create_scene
+ end
end
redef class GamnitDisplay
# Texture composed of pixels, loaded from the assets folder by default
#
# Most textures should be created with `App` (as attributes)
-# for the method `on_create` to load them.
+# for the method `create_scene` to load them.
#
# ~~~
# import gamnit::flat
# # Create the texture object, it will be loaded automatically
# var texture = new Texture("path/in/assets.png")
#
-# redef fun on_create()
+# redef fun create_scene()
# do
-# # Let `on_create` load the texture
+# # Let `create_scene` load the texture
# super
#
# # Use the texture
# end
# ~~~
#
-# Otherwise, they can be loaded and error checked explicitly after `on_create`.
+# Otherwise, they can be loaded and error checked explicitly after `create_scene`.
#
# ~~~nitish
# var texture = new Texture("path/in/assets.png")
#
# ~~~
# redef class App
-# redef fun on_create
+# redef fun create_scene
# do
# super
#