don't reset actors each frame by default; make the behavior toggleable

This commit is contained in:
Jill 2022-12-09 21:55:17 +03:00
parent 5e3713d14b
commit 5388b2cafe
3 changed files with 18 additions and 6 deletions

View File

@ -200,9 +200,11 @@ 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 `resetOnFrameStart`:
```lua ```lua
resetOnFrameStart(true)
local quad = Quad() local quad = Quad()
quad:xy(scx, scy) quad:xy(scx, scy)
quad:zoomto(60, 60) quad:zoomto(60, 60)
@ -217,7 +219,7 @@ function uranium.update()
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 [`uranium.init`](#uraniuminit) callback:
```lua ```lua
local sprite = Sprite() local sprite = Sprite()
@ -235,6 +237,14 @@ sprite:addcommand('Init', function(self)
end) end)
``` ```
Or, you can disable the frame resetting functionality individually:
```lua
resetOnFrameStart(true)
local sprite = Sprite()
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.
@ -1134,6 +1144,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)
resetActorOnFrameStart(quad)
-- define a sprite -- define a sprite
local sprite = Sprite('docs/uranium.png') local sprite = Sprite('docs/uranium.png')
@ -1363,12 +1374,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() function uranium.update()
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)

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)
resetActorOnFrameStart(quad)
-- define a sprite -- define a sprite
local sprite = Sprite('docs/uranium.png') local sprite = Sprite('docs/uranium.png')

@ -1 +1 @@
Subproject commit f4e8c1df7ca44eff65662d636fcb1ddb74254121 Subproject commit 0a1805e6fa8448bcf38b0dde5a77e64213e49bc8