https://github.com/u16kuma/defunico
DefUniCo is a coroutine library for Defold game engine.
https://github.com/u16kuma/defunico
defold-game-engine
Last synced: 3 months ago
JSON representation
DefUniCo is a coroutine library for Defold game engine.
- Host: GitHub
- URL: https://github.com/u16kuma/defunico
- Owner: u16kuma
- License: mit
- Created: 2018-03-25T07:46:24.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2018-04-03T14:24:48.000Z (about 7 years ago)
- Last Synced: 2025-02-28T16:00:48.108Z (4 months ago)
- Topics: defold-game-engine
- Language: Lua
- Size: 17.6 KB
- Stars: 11
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
- awesome-defold - DefUniCo
README
# DefUniCo
DefUniCo is a coroutine library for Defold game engine.
The library is useful when you want to write coroutine like Unity3D in Defold.# Installation
You can use DefUniCo in your own project by adding this project as a [Defold library dependency](https://www.defold.com/manuals/libraries/).
Open your game.project file and in the dependencies field under project add:```
https://github.com/u16kuma/defunico/archive/master.zip
```Or point to the ZIP file of a [specific DefUniCo release](https://github.com/u16kuma/defunico/releases).
# Usage
DefUniCo is very easy to use.
All you need to do is to write template code.test.script
```lua
local defunico = require("defunico.defunico")
function init(self)
defunico.init(self)
end
function update(self, dt)
self.update_coroutine(dt)
end
```Let's try write coroutine!
```lua
function init(self)
defunico.init(self)-- Please write coroutine code under the defunico.init
self.start_coroutine(function(self)
-- wait one second
wait_seconds(1)print("One second has passed.")
end)
end
```Coroutines can be stopped by adding this code.
```lua
local co = self.start_coroutine(function() ... end)
self.stop_coroutine(co)
```Coroutine wait some wait_* function.
```lua
self.start_coroutine(function(self)-- wait one second
wait_seconds(1)-- wait one second
wait_msec(1000)
-- wait one second (60 fps)
wait_frame(60)-- wait one second (60 fps)
local frame = 0
wait_until(function()
frame = frame + 1
return frame >= 60
end)-- wait one second (60 fps)
frame = 0
wait_while(function()
frame = frame + 1
return frame <= 60
end)-- need to write self.on_input_coroutine to on_input
local input_pack = self.wait_until_input(function(action_id, action)
return action_id == hash("touch")
end)-- need to write self.on_message_coroutine to on_message
local msg_pack = self.wait_until_message(function(message_id, message, sender)
return message_id == hash("update")
end)end)
```