Compare commits

...

10 Commits
1.0-b2 ... main

Author SHA1 Message Date
Jill a08da0ebd6
input: fix uranium.call typo 2023-06-02 12:04:10 +03:00
Jill 1534c21eb4
typo 2023-05-04 22:54:45 +03:00
Jill 5b5ed353bd
stdlib.easable: rewrite 2023-05-04 22:13:22 +03:00
Jill ee6c543c57
stdlib.aft: aftSetup for convenience 2023-05-04 22:10:23 +03:00
Jill dcc4848989
update docs to account for event system switch 2023-05-04 22:07:17 +03:00
Jill 89e3b71ab5
config library 2023-05-04 21:40:42 +03:00
Jill 59ca5e743d
switch to Normal event system 2023-05-04 17:52:30 +03:00
Jill 5388b2cafe don't reset actors each frame by default; make the behavior toggleable 2022-12-09 21:55:17 +03:00
Jill 5e3713d14b add texture func 2022-10-29 15:02:45 +03:00
Jill e860423821 add mirin template's license 2022-10-18 20:12:54 +03:00
5 changed files with 130 additions and 93 deletions

204
MANUAL.md
View File

@ -30,16 +30,21 @@ Uranium Template originally formed during the creation of a currently unreleased
- [`ActorFrame`](#actorframe) - [`ActorFrame`](#actorframe)
- [`ActorScroller`](#actorscroller) - [`ActorScroller`](#actorscroller)
- [`BitmapText`](#bitmaptext) - [`BitmapText`](#bitmaptext)
- [Textures](#textures)
- [Shaders](#shaders) - [Shaders](#shaders)
- [Callback usage](#callback-usage) - [Callback usage](#callback-usage)
- [Default callbacks](#default-callbacks) - [Default callbacks](#default-callbacks)
- [`uranium.update(dt: number)`](#uraniumupdatedt-number) - [`update(dt: number)`](#updatedt-number)
- [`uranium.init()`](#uraniuminit) - [`init()`](#init)
- [`uranium.ready()`](#uraniumready) - [`ready()`](#ready)
- [`uranium.exit()`](#uraniumexit) - [`exit()`](#exit)
- [`uranium.focus(hasFocus: boolean)`](#uraniumfocushasfocus-boolean) - [`focus(hasFocus: boolean)`](#focushasfocus-boolean)
- [Custom callbacks](#custom-callbacks) - [Custom callbacks](#custom-callbacks)
- [Requiring files](#requiring-files) - [Requiring files](#requiring-files)
- [Configuration](#configuration)
- [`uranium.config.resetOnFrameStart(bool: boolean)`](#uraniumconfigresetonframestartbool-boolean)
- [`uranium.config.resetActorOnFrameStart(actor: Actor, bool: boolean?)`](#uraniumconfigresetactoronframestartactor-actor-bool-boolean)
- [`uranium.config.hideThemeActors(bool: boolean)`](#uraniumconfighidethemeactorsbool-boolean)
- [Standard library](#standard-library) - [Standard library](#standard-library)
- [Importing modules](#importing-modules) - [Importing modules](#importing-modules)
- [`vector2D`](#vector2d) - [`vector2D`](#vector2d)
@ -87,8 +92,8 @@ Uranium Template originally formed during the creation of a currently unreleased
- [`input.keyboardEquivalent`](#inputkeyboardequivalent) - [`input.keyboardEquivalent`](#inputkeyboardequivalent)
- [`input.getInput(i: string, pn: number | nil): number`](#inputgetinputi-string-pn-number--nil-number) - [`input.getInput(i: string, pn: number | nil): number`](#inputgetinputi-string-pn-number--nil-number)
- [`input.isDown(i: string, pn: number | nil): number`](#inputisdowni-string-pn-number--nil-number) - [`input.isDown(i: string, pn: number | nil): number`](#inputisdowni-string-pn-number--nil-number)
- [`uranium.press(input: inputType, pn: number)`](#uraniumpressinput-inputtype-pn-number) - [`press(input: inputType, pn: number)`](#pressinput-inputtype-pn-number)
- [`uranium.release(input: inputType, pn: number)`](#uraniumreleaseinput-inputtype-pn-number) - [`release(input: inputType, pn: number)`](#releaseinput-inputtype-pn-number)
- [A note about keyboard inputs](#a-note-about-keyboard-inputs) - [A note about keyboard inputs](#a-note-about-keyboard-inputs)
- [`bitop`](#bitop) - [`bitop`](#bitop)
- [`scheduler`](#scheduler) - [`scheduler`](#scheduler)
@ -125,7 +130,7 @@ Uranium Template originally formed during the creation of a currently unreleased
- [`profiler`](#profiler) - [`profiler`](#profiler)
- [`util`](#util) - [`util`](#util)
- [`aft`](#aft) - [`aft`](#aft)
- [`noautplay`](#noautplay) - [`noautoplay`](#noautoplay)
- [`eternalfile`](#eternalfile) - [`eternalfile`](#eternalfile)
- [`uwuify`](#uwuify) - [`uwuify`](#uwuify)
- [Examples](#examples) - [Examples](#examples)
@ -166,7 +171,7 @@ Afterwards, it should be safe to zip everything up and send it over!
`main.lua` is the entry-point for your code! From there, you can do the following: `main.lua` is the entry-point for your code! From there, you can do the following:
- [Define some actors](#defining-actors), and [call initialization methods on those actors](#initializing-actors) to set them up - [Define some actors](#defining-actors), and [call initialization methods on those actors](#initializing-actors) to set them up
- [Define callbacks](#callback-usage), such as the [update](#uraniumupdatedt-number) callback - [Define callbacks](#callback-usage), such as the [update](#updatedt-number) callback
- [Require more files in](#requiring-files)! Splitting your code into neat little modules is always good practice. - [Require more files in](#requiring-files)! Splitting your code into neat little modules is always good practice.
- Make use of the expansive [standard library](#standard-library), like the [vector](#vector2d) or [color](#color) classes - Make use of the expansive [standard library](#standard-library), like the [vector](#vector2d) or [color](#color) classes
@ -199,31 +204,33 @@ text:rotationz(30)
text:diffuse(1, 0.8, 0.8, 1) text:diffuse(1, 0.8, 0.8, 1)
``` ```
All methods that you run upon definition will be ran again at the start of every frame: All methods that you run upon definition will be ran again at the start of every frame with `uranium.config.resetOnFrameStart`:
```lua ```lua
uranium.config.resetOnFrameStart(true)
local quad = Quad() local quad = Quad()
quad:xy(scx, scy) quad:xy(scx, scy)
quad:zoomto(60, 60) quad:zoomto(60, 60)
quad:diffusealpha(1) quad:diffusealpha(1)
function uranium.update() uranium.on('update',
-- doesn't need a reset! it'll automatically zoomto 60, 60 and set its alpha to 1 -- doesn't need a reset! it'll automatically zoomto 60, 60 and set its alpha to 1
quad:Draw() quad:Draw()
quad:zoomto(120, 120) quad:zoomto(120, 120)
quad:diffusealpha(0.5) quad:diffusealpha(0.5)
quad:Draw() quad:Draw()
end end)
``` ```
If you want to avoid this, or otherwise call getter methods, use the [`uranium.init`](#uraniuminit) callback: If you want to avoid this for individual actors, or otherwise call getter methods, use the [`init`](#init) callback:
```lua ```lua
local sprite = Sprite() local sprite = Sprite()
function uranium.init() uranium.on('init', function()
someTexture = sprite:GetTexture() someTexture = sprite:GetTexture()
end end)
``` ```
Alternatively, you can also use the actors' individual `InitCommand`s: Alternatively, you can also use the actors' individual `InitCommand`s:
@ -234,6 +241,14 @@ sprite:addcommand('Init', function(self)
end) end)
``` ```
Or, you can disable the frame resetting functionality individually:
```lua
uranium.config.resetOnFrameStart(true)
local sprite = Sprite()
uranium.config.resetActorOnFrameStart(sprite, false)
sprite:Draw() -- will not be called per-frame
```
### Accessing raw actors ### Accessing raw actors
As you may have noticed, when you print an actor defined with Uranium, it won't show up as an actor - it'll show up as a "proxy" of an actor. This is because we can't actually get actors created on demand in NotITG - what happens instead is you get an object that _acts_ like an actor by calling all the same methods you pass into it, but isn't really one. As you may have noticed, when you print an actor defined with Uranium, it won't show up as an actor - it'll show up as a "proxy" of an actor. This is because we can't actually get actors created on demand in NotITG - what happens instead is you get an object that _acts_ like an actor by calling all the same methods you pass into it, but isn't really one.
@ -296,9 +311,9 @@ setDrawFunction(af, function() -- necessary to call this instead of af.SetDrawFu
sprite:Draw() sprite:Draw()
end) end)
function uranium.update() uranium.on('update', function()
af:Draw() -- would draw quad and sprite af:Draw() -- would draw quad and sprite
end end)
``` ```
**Nested AFs are supported.** As with all complicated things in this template, check out the [`ActorFrame` example](#simple-actorframe-setup) for a simple working setup. **Nested AFs are supported.** As with all complicated things in this template, check out the [`ActorFrame` example](#simple-actorframe-setup) for a simple working setup.
@ -311,13 +326,13 @@ setDrawFunction(af, function(x, y)
quad:Draw() quad:Draw()
end) end)
function uranium.update() uranium.on('update', function()
for x = 0, 3 do for x = 0, 3 do
for y = 0, 3 do for y = 0, 3 do
af:Draw(x, y) af:Draw(x, y)
end end
end end
end end)
``` ```
#### `ActorScroller` #### `ActorScroller`
@ -340,6 +355,17 @@ However, providing custom fonts is a bit tedious due to a [vanilla bug](https://
local text = BitmapText('../src/_inter v 22px.ini', 'test') local text = BitmapText('../src/_inter v 22px.ini', 'test')
``` ```
#### Textures
For convinience, `Texture` is a function that will give you a `RageTexture` from a filename without the actor. Equivalent to:
```lua
local sprite = Sprite('filename.png')
sprite:hidden(1)
local texture = sprite:GetTexture()
return texture
```
### Shaders ### Shaders
Shaders cannot be manually defined on actors [due to a technical limitation](https://discord.com/channels/227650173256466432/666629297544495124/1022119161415077909); plus, it wouldn't make much sense to integrate them in the same way that NotITG integrates shaders with the current XML behavior. In order to give an actor a shader, you need to define them seperately: Shaders cannot be manually defined on actors [due to a technical limitation](https://discord.com/channels/227650173256466432/666629297544495124/1022119161415077909); plus, it wouldn't make much sense to integrate them in the same way that NotITG integrates shaders with the current XML behavior. In order to give an actor a shader, you need to define them seperately:
@ -349,7 +375,7 @@ local sprite = Sprite('docs/uranium.png')
local shader = Shader('src/shader.frag') -- returns a RageShaderProgram local shader = Shader('src/shader.frag') -- returns a RageShaderProgram
``` ```
Afterwards, call `setShader` on your actor. You can call this outside of `uranium.init`, if you like. Afterwards, call `setShader` on your actor. You can call this outside of `init`, if you like.
```lua ```lua
setShader(actor, shader) setShader(actor, shader)
@ -391,15 +417,15 @@ Check [the shader example](#shader-test) if you just want something to play arou
## Callback usage ## Callback usage
Uranium uses a unique callback system - to define a callback, you define a function under `uranium.` with your desired callback name: Callbacks are defined with `uranium.on`:
```lua ```lua
function uranium.update(dt) uranium.on('update', function(dt)
-- runs every frame -- runs every frame
end end)
``` ```
You can do this as many times as you like - it'll call every single function that's defined as `uranium.update`, not just the last! You can do this as many times as you like - it'll call every single function that's defined as `update`, not just the last!
If you return a non-falsy value in a callback, however, it'll cancel every other callback after it. This can be useful for, eg. capturing inputs and ensuring they don't get passed through to other callbacks on accident. If you return a non-falsy value in a callback, however, it'll cancel every other callback after it. This can be useful for, eg. capturing inputs and ensuring they don't get passed through to other callbacks on accident.
@ -407,19 +433,19 @@ If you return a non-falsy value in a callback, however, it'll cancel every other
These are the callbacks that are built into Uranium: These are the callbacks that are built into Uranium:
#### `uranium.update(dt: number)` #### `update(dt: number)`
Called every frame. `dt` is the time passed since the last frame, the "deltatime". Called every frame. `dt` is the time passed since the last frame, the "deltatime".
#### `uranium.init()` #### `init()`
Called once on `OnCommand`. Every actor has been created, and the game should be starting shortly. Called once on `OnCommand`. Every actor has been created, and the game should be starting shortly.
#### `uranium.ready()` #### `ready()`
Fired on the first tick. A later version of `init()` where more things should be safe to use. Fired on the first tick. A later version of `init()` where more things should be safe to use.
#### `uranium.exit()` #### `exit()`
_Should_ call when the player exits the file. **Not properly tested yet.** _Should_ call when the player exits the file. **Not properly tested yet.**
#### `uranium.focus(hasFocus: boolean)` #### `focus(hasFocus: boolean)`
Called whenever the window loses/gains focus. You can use this to reduce render quality on alt-tab. Called whenever the window loses/gains focus. You can use this to reduce render quality on alt-tab.
### Custom callbacks ### Custom callbacks
@ -427,15 +453,15 @@ Called whenever the window loses/gains focus. You can use this to reduce render
Custom callbacks require no extra setup. Define your callback like usual: Custom callbacks require no extra setup. Define your callback like usual:
```lua ```lua
function uranium.somethingHappened(value) uranium.on('somethingHappened', function(value)
-- ... -- ...
end end)
``` ```
Then all you need to do to call it is: Then all you need to do to call it is:
```lua ```lua
uranium:call('somethingHappened', extra, values, go, here) uranium.call('somethingHappened', extra, values, go, here)
``` ```
Callbacks support as many extra values as Lua supports arguments in a function - so let's just say you won't be running out of them any time soon. Callbacks support as many extra values as Lua supports arguments in a function - so let's just say you won't be running out of them any time soon.
@ -461,6 +487,22 @@ Your setup would print `'hello!'`.
All [standard library](#standard-library) modules are required with `require`, see further notes in [**Importing modules**](#importing-modules). All [standard library](#standard-library) modules are required with `require`, see further notes in [**Importing modules**](#importing-modules).
## Configuration
Uranium Template's base functionality can be configured using `uranium.config`. You can access the raw values by requiring `uranium.config`, but this is currently undocumented.
#### `uranium.config.resetOnFrameStart(bool: boolean)`
Toggle actor resetting on frame start behavior by default. _(Default: `false`)_
#### `uranium.config.resetActorOnFrameStart(actor: Actor, bool: boolean?)`
Toggle actor resetting on frame start for individual actors. `bool` defaults to the opposite of your `resetOnFrameStart` config.
#### `uranium.config.hideThemeActors(bool: boolean)`
Toggle if theme actors (lifebars, scores, song names, etc.) are hidden. Must be toggled **before** `init`. _(Default: `true`)_
## Standard library ## Standard library
The Uranium Template standard library is split up into a few convinient modules. This section aims to comprehensively document them all. The Uranium Template standard library is split up into a few convinient modules. This section aims to comprehensively document them all.
@ -700,11 +742,11 @@ n:add(value)
n:reset(value) n:reset(value)
-- then, in your update function -- then, in your update function
function uranium.update(dt) uranium.on('update', function(dt)
n(dt) -- multiply this image by some value to speed it up n:update(dt) -- multiply this image by some value to speed it up
print(n.a) -- retrieve the eased value print(n.eased) -- retrieve the eased value
print(n.toa) -- retrieve the target value it's easing towards print(n.target) -- retrieve the target value it's easing towards
end end)
``` ```
#### `easable(default: number): easable` #### `easable(default: number): easable`
@ -713,15 +755,15 @@ Creates a new easable, setting the default to `default`. Can technically be anyt
#### `easable:set(new: number): void` #### `easable:set(new: number): void`
Sets the target value (`toa`) to `new`, easing the current value to the new value. Sets the target value (`target`) to `new`, easing the current value to the new value.
#### `easable:add(new: number): void` #### `easable:add(new: number): void`
Equivalent to `easable:add(easable.toa + new)`. Equivalent to `easable:add(easable.target + new)`.
#### `easable:reset(new: number): void` #### `easable:reset(new: number): void`
Sets the current (`a`) and target (`toa`) values to `new`, **not** easing the current value to the new value. Sets the current (`eased`) and target (`target`) values to `new`, **not** easing the current value to the new value.
#### Operations #### Operations
@ -813,11 +855,11 @@ input.inputs[1][input.inputType.Left] == input.getInput('Left', 1)
Shorthand for `input.getInput(i, pn) ~= -1`. If `pn` is not provided, players are ignored and it checks if either of the players have the input held down Shorthand for `input.getInput(i, pn) ~= -1`. If `pn` is not provided, players are ignored and it checks if either of the players have the input held down
#### `uranium.press(input: inputType, pn: number)` #### `press(input: inputType, pn: number)`
Called when a player presses on a certain key. Called when a player presses on a certain key.
#### `uranium.release(input: inputType, pn: number)` #### `release(input: inputType, pn: number)`
Same as [`uranium.press`](#uraniumpressinput-inputtype), except for releasing a key. Same as [`press`](#pressinput-inputtype), except for releasing a key.
#### A note about keyboard inputs #### A note about keyboard inputs
@ -863,7 +905,7 @@ Schedules a function to run in a specific amount of time. `when` is in seconds.
#### `scheduler.scheduleInTicks(when: number, func: function): number` #### `scheduler.scheduleInTicks(when: number, func: function): number`
Schedules a function to run in a specific amount of `uranium.update` calls/ticks. Schedules a function to run in a specific amount of `update` calls/ticks.
#### `scheduler.unschedule(i: index): void` #### `scheduler.unschedule(i: index): void`
@ -931,13 +973,13 @@ local counter = {
savedata.s(counter) savedata.s(counter)
function uranium.init() uranium.on('init', function()
print(counter.n) --> could be different from 0! print(counter.n) --> could be different from 0!
end end)
function uranium.update() uranium.on('update', function()
counter.n = counter.n + 1 -- this will be saved the next time savedata.save is called counter.n = counter.n + 1 -- this will be saved the next time savedata.save is called
end end)
``` ```
By default, the name that's used for your module will be the folder your Lua file is located in, followed by its filename. **This means you should not rely on the automatic name generation if your Lua file rests at the root of your file or if you're calling this function via `loadstring` or similar** as it will create unpredictable module names that will change between setups and sometimes even game restarts. You can pass in any string you like to `name`, as long as it's unique in your project, to override this behavior. By default, the name that's used for your module will be the folder your Lua file is located in, followed by its filename. **This means you should not rely on the automatic name generation if your Lua file rests at the root of your file or if you're calling this function via `loadstring` or similar** as it will create unpredictable module names that will change between setups and sometimes even game restarts. You can pass in any string you like to `name`, as long as it's unique in your project, to override this behavior.
@ -948,7 +990,7 @@ Saves the savedata onto the user's profile. It waits a single tick to do so and
#### `savedata.load(): void` #### `savedata.load(): void`
Loads the savedata. _Shouldn't be called manually; this is automatically called on [`uranium.init()`](#uraniuminit)._ Loads the savedata. _Shouldn't be called manually; this is automatically called on [`init()`](#init)._
#### `savedata.getLastSave(): string[] | nil` #### `savedata.getLastSave(): string[] | nil`
@ -956,7 +998,7 @@ Gets the last save time that persists between game restarts in the format `{hour
#### `savedata.enableAutosave(): void` #### `savedata.enableAutosave(): void`
Enables autosave via [`uranium.exit()`](#uraniumexit). Should hopefully mean data should never get lost. Enables autosave via [`exit()`](#exit). Should hopefully mean data should never get lost.
### `env` ### `env`
@ -1053,25 +1095,18 @@ There's _a bit too many_ functions to document, so I'd recommend just looking th
### `aft` ### `aft`
An AFT setup library. Sets up sprites and AFTs with `sprite` and `aft`, respectively, making them ready for texturing use. An AFT setup library. Sets up sprites and AFTs with `sprite` and `aft`, or all-in-one with `aftSetup`, making them ready for texturing use.
```lua ```lua
local aftSetup = require('stdlib.aft') local aftlib = require('stdlib.aft')
local aft = ActorFrameTexture() -- aftSprite is a Sprite, set to the texture of aft, an ActorFrameTexture
local aft, aftSprite = aftlib.aftSetup()
local aftSprite = Sprite()
aftSetup.sprite(aftSprite)
aft:addcommand('Init', function(self)
aftSetup.aft(aft) -- put this here; else it'll recreate it every frame!
aftSprite:SetTexture(self:GetTexture())
end)
``` ```
### `noautplay` ### `noautoplay`
A single function which can be called before `uranium.ready()` to disable autoplay for the duration of the file if the player has it on. ***Not tested.*** A single function which can be called before `ready()` to disable autoplay for the duration of the file if the player has it on. ***Not tested.***
```lua ```lua
require('stdlib.noautoplay')() require('stdlib.noautoplay')()
@ -1103,9 +1138,9 @@ Here are a couple of examples. All of these are standalone `main.lua` files that
local text = BitmapText('common', 'Hello, world!') local text = BitmapText('common', 'Hello, world!')
text:xy(scx, scy) text:xy(scx, scy)
function uranium.update() uranium.on('update', function()
text:Draw() text:Draw()
end end)
``` ```
### Default Uranium Template code ### Default Uranium Template code
@ -1122,6 +1157,7 @@ quad:xy(scx, scy)
quad:zoom(120) quad:zoom(120)
quad:diffuse(0.8, 1, 0.7, 1) quad:diffuse(0.8, 1, 0.7, 1)
quad:skewx(0.2) quad:skewx(0.2)
uranium.config.resetActorOnFrameStart(quad)
-- define a sprite -- define a sprite
local sprite = Sprite('docs/uranium.png') local sprite = Sprite('docs/uranium.png')
@ -1135,7 +1171,7 @@ text:xy(scx, scy + 100)
-- update gets called every frame -- update gets called every frame
-- dt here refers to deltatime - the time that has passed since the last frame! -- dt here refers to deltatime - the time that has passed since the last frame!
function uranium.update(dt) uranium.on('update', function(dt)
-- let's rotate our quad -- let's rotate our quad
quad:rotationz(t * 80) quad:rotationz(t * 80)
-- then shove it to the screen - similar to a drawfunction! -- then shove it to the screen - similar to a drawfunction!
@ -1163,7 +1199,7 @@ function uranium.update(dt)
-- wag the text -- wag the text
text:rotationz(math.sin(t * 2) * 10) text:rotationz(math.sin(t * 2) * 10)
text:Draw() text:Draw()
end end)
``` ```
### Simple platformer base ### Simple platformer base
@ -1195,15 +1231,15 @@ local vel = vector(0, 0)
local hasHitGround = true -- let's define this so that you can't jump mid-air local hasHitGround = true -- let's define this so that you can't jump mid-air
-- called whenever the player recieves an input -- called whenever the player recieves an input
function uranium.press(i) uranium.on('press', function(i)
if i == input.inputType.Up and hasHitGround then if i == input.inputType.Up and hasHitGround then
vel.y = vel.y - JUMP_FORCE vel.y = vel.y - JUMP_FORCE
hasHitGround = false hasHitGround = false
return true -- input eaten! further callbacks won't recieve this return true -- input eaten! further callbacks won't recieve this
end end
end end)
function uranium.update(dt) uranium.on('update', function(dt)
-- respond to l/r inputs -- respond to l/r inputs
if input.isDown('Left') then if input.isDown('Left') then
vel.x = vel.x - SPEED vel.x = vel.x - SPEED
@ -1239,7 +1275,7 @@ function uranium.update(dt)
-- draw the ground -- draw the ground
ground:Draw() ground:Draw()
end end)
``` ```
### AFTs ### AFTs
@ -1274,7 +1310,7 @@ end)
local text = BitmapText('common', 'uranium template!') local text = BitmapText('common', 'uranium template!')
text:xy(scx, scy) text:xy(scx, scy)
function uranium.update(dt) uranium.on('update', function(dt)
coverQuad:Draw() coverQuad:Draw()
aftSprite:Draw() aftSprite:Draw()
@ -1289,7 +1325,7 @@ function uranium.update(dt)
aft:Draw() aft:Draw()
text:Draw() text:Draw()
end end)
``` ```
### Shader test ### Shader test
@ -1351,12 +1387,12 @@ void main() {
gl_FragColor = col * color; gl_FragColor = col * color;
} }
]]) ]])
shader:uniform1f('yo', 1)
shader:uniform1f('scale', 0.25)
setShader(sprite, shader) setShader(sprite, shader)
function uranium.update() uranium.on('update', function()
shader:uniform1f('yo', 1)
shader:uniform1f('scale', 0.25)
shader:uniform1f('tx', t) shader:uniform1f('tx', t)
shader:uniform1f('ty', t) shader:uniform1f('ty', t)
@ -1367,7 +1403,7 @@ function uranium.update()
reset(sprite) reset(sprite)
shader:uniform1f('yo', 0) shader:uniform1f('yo', 0)
sprite:Draw() sprite:Draw()
end end)
``` ```
### Savedata example ### Savedata example
@ -1388,7 +1424,7 @@ savedata.s(save)
local text = BitmapText('common', '') local text = BitmapText('common', '')
text:xy(scx, scy) text:xy(scx, scy)
function uranium.press(key) uranium.on('press', function(key)
if key == input.inputType.Left then if key == input.inputType.Left then
save.leftPresses = save.leftPresses + 1 save.leftPresses = save.leftPresses + 1
elseif key == input.inputType.Right then elseif key == input.inputType.Right then
@ -1396,9 +1432,9 @@ function uranium.press(key)
elseif key == input.inputType.Down then elseif key == input.inputType.Down then
savedata.save() savedata.save()
end end
end end)
function uranium.update(dt) uranium.on('update', function(dt)
text:settext( text:settext(
'left presses: ' .. save.leftPresses .. '\n' .. 'left presses: ' .. save.leftPresses .. '\n' ..
'right presses: ' .. save.rightPresses 'right presses: ' .. save.rightPresses
@ -1410,7 +1446,7 @@ function uranium.update(dt)
text:settext('saving!') text:settext('saving!')
text:Draw() text:Draw()
end end
end end)
``` ```
### Simple ActorFrame setup ### Simple ActorFrame setup
@ -1463,9 +1499,9 @@ setDrawFunction(af, function()
sprite:Draw() sprite:Draw()
end) end)
function uranium.update() uranium.on('update', function()
af:Draw() af:Draw()
end end)
``` ```
## Credits ## Credits

View File

@ -28,18 +28,18 @@ Then define callbacks with a simple function definition:
```lua ```lua
local timer = 0 local timer = 0
function uranium.update(dt) uranium.on('update', function(dt)
timer = timer + dt timer = timer + dt
end end)
``` ```
And then define the draw order of your actors with simple method calls, similar to DrawFunctions: And then define the draw order of your actors with simple method calls, similar to DrawFunctions:
```lua ```lua
function uranium.update() uranium.on('update', function()
quad:rotationz(t * 50) quad:rotationz(t * 50)
quad:Draw() quad:Draw()
end end)
``` ```
It comes with an extensive standard library, including common game-development needs like: It comes with an extensive standard library, including common game-development needs like:

View File

@ -10,6 +10,7 @@ quad:xy(scx, scy)
quad:zoom(120) quad:zoom(120)
quad:diffuse(0.8, 1, 0.7, 1) quad:diffuse(0.8, 1, 0.7, 1)
quad:skewx(0.2) quad:skewx(0.2)
uranium.config.resetActorOnFrameStart(quad)
-- define a sprite -- define a sprite
local sprite = Sprite('docs/uranium.png') local sprite = Sprite('docs/uranium.png')
@ -23,7 +24,7 @@ text:xy(scx, scy + 100)
-- update gets called every frame -- update gets called every frame
-- dt here refers to deltatime - the time that has passed since the last frame! -- dt here refers to deltatime - the time that has passed since the last frame!
function uranium.update(dt) uranium.on('update', function(dt)
-- let's rotate our quad -- let's rotate our quad
quad:rotationz(t * 80) quad:rotationz(t * 80)
-- then shove it to the screen - similar to a drawfunction! -- then shove it to the screen - similar to a drawfunction!
@ -51,4 +52,4 @@ function uranium.update(dt)
-- wag the text -- wag the text
text:rotationz(math.sin(t * 2) * 10) text:rotationz(math.sin(t * 2) * 10)
text:Draw() text:Draw()
end end)

@ -1 +1 @@
Subproject commit 99f8ab7f8bae6a95419881bb5dbe105c807ad3ba Subproject commit 912bb8f234023e9020e9091b85a4e096b0ecea43

View File

@ -1,4 +1,4 @@
#!/bin/bash #!/bin/bash
rm template/release.lua rm template/uranium/release.lua
read -p "enter release version: " version read -p "enter release version: " version
sed -e "s/branch = 'unknown'/branch = '$(git rev-parse --abbrev-ref HEAD)'/" -e "s/commit = 'unknown'/commit = '$(git rev-parse --short HEAD)'/" -e "s/version = 'unknown'/version = '$version'/" template/release_blank.lua > template/release.lua sed -e "s/branch = 'unknown'/branch = '$(git rev-parse --abbrev-ref HEAD)'/" -e "s/commit = 'unknown'/commit = '$(git rev-parse --short HEAD)'/" -e "s/version = 'unknown'/version = '$version'/" template/uranium/release_blank.lua > template/uranium/release.lua