mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-14 16:09:06 +07:00
add example scripts
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
{
|
{
|
||||||
"components" : {
|
"components" : {
|
||||||
"scene" : {}
|
"scene" : {},
|
||||||
|
"behaviour" : {
|
||||||
|
"script" : "../scripts/sample_07/sample_07.lua"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
"children" : [{
|
"children" : [{
|
||||||
"prototype" : "../prefabs/camera_prefab.json"
|
"prototype" : "../prefabs/camera_prefab.json"
|
||||||
@@ -10,20 +13,26 @@
|
|||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [0,0,0],
|
"translation" : [0,0,0],
|
||||||
"scale" : 20
|
"scale" : 20
|
||||||
|
},
|
||||||
|
"behaviour" : {
|
||||||
|
"script" : "../scripts/sample_07/gnome.lua"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, {
|
},{
|
||||||
"prototype" : "../prefabs/label_sdf_prefab.json",
|
"prototype" : "../prefabs/label_sdf_prefab.json",
|
||||||
"components" : {
|
"components" : {
|
||||||
"label" : {
|
"label" : {
|
||||||
"text" : "Hello World!",
|
"text" : "FPS: ",
|
||||||
"valign" : "center",
|
"halign" : "left",
|
||||||
"outline_width" : 0.5,
|
"outline_width" : 0.5,
|
||||||
"outline_color" : [0,0,0,255]
|
"outline_color" : [0,0,0,255]
|
||||||
},
|
},
|
||||||
"actor" : {
|
"actor" : {
|
||||||
"translation" : [0.5,-180.5,0],
|
"translation" : [-315,-235,0],
|
||||||
"scale" : 2
|
"scale" : 1
|
||||||
|
},
|
||||||
|
"behaviour" : {
|
||||||
|
"script" : "../scripts/sample_07/fps_label.lua"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}]
|
}]
|
||||||
|
|||||||
40
samples/bin/library/scripts/sample_07/fps_label.lua
Normal file
40
samples/bin/library/scripts/sample_07/fps_label.lua
Normal file
@@ -0,0 +1,40 @@
|
|||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- private
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---@class fps_label_meta
|
||||||
|
---@field last_fps number
|
||||||
|
|
||||||
|
---@param meta fps_label_meta
|
||||||
|
---@param go gobject
|
||||||
|
local function update_label_text(meta, go)
|
||||||
|
local curr_fps = the_engine.frame_rate
|
||||||
|
if meta.last_fps ~= curr_fps then
|
||||||
|
meta.last_fps = curr_fps
|
||||||
|
go.label.text = "FPS: " .. curr_fps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- meta
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param meta fps_label_meta
|
||||||
|
---@param go gobject
|
||||||
|
function M.on_start(meta, go)
|
||||||
|
meta.last_fps = -1
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param meta fps_label_meta
|
||||||
|
---@param go gobject
|
||||||
|
function M.on_update(meta, go)
|
||||||
|
update_label_text(meta, go)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
49
samples/bin/library/scripts/sample_07/gnome.lua
Normal file
49
samples/bin/library/scripts/sample_07/gnome.lua
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- private
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
---@class gnome_meta
|
||||||
|
---@field life_time number
|
||||||
|
|
||||||
|
---@param meta gnome_meta
|
||||||
|
---@param go gobject
|
||||||
|
local function update_life_time(meta, go)
|
||||||
|
meta.life_time = meta.life_time - the_engine.delta_time
|
||||||
|
if meta.life_time <= 0 then
|
||||||
|
go:destroy()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param meta gnome_meta
|
||||||
|
---@param go gobject
|
||||||
|
local function update_gnome_rotation(meta, go)
|
||||||
|
go.actor.node.rotation = q4f.make_from_euler_angles(
|
||||||
|
radf.new(),
|
||||||
|
radf.new(the_engine.time),
|
||||||
|
radf.new())
|
||||||
|
end
|
||||||
|
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
--
|
||||||
|
-- meta
|
||||||
|
--
|
||||||
|
-- -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param meta gnome_meta
|
||||||
|
---@param go gobject
|
||||||
|
function M.on_start(meta, go)
|
||||||
|
meta.life_time = 5
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param meta gnome_meta
|
||||||
|
---@param go gobject
|
||||||
|
function M.on_update(meta, go)
|
||||||
|
update_life_time(meta, go)
|
||||||
|
update_gnome_rotation(meta, go)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
22
samples/bin/library/scripts/sample_07/sample_07.lua
Normal file
22
samples/bin/library/scripts/sample_07/sample_07.lua
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
---@param go gobject
|
||||||
|
function M:on_start(go)
|
||||||
|
the_debug:trace("sample_07: on_start")
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param go gobject
|
||||||
|
function M:on_update(go)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param go gobject
|
||||||
|
---@param type string
|
||||||
|
---@param event any
|
||||||
|
function M:on_event(go, type, event)
|
||||||
|
end
|
||||||
|
|
||||||
|
---@param go gobject
|
||||||
|
function M:on_shutdown(go)
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Reference in New Issue
Block a user