Enjl wrote: ↑Tue Dec 08, 2020 3:36 am
The frames of all bgos of an Id are synced and not exposed, so it would be safer to try and use an image drawn entirely in lua for this. Here is a small setup that could work for your use case, with some modification of the ALL_CAPS properties at the top:
Code: Select all
local OBJECT_IMAGE = Graphics.loadImage("NAME_OF_THE_OBJECT.png")
local FRAME_COUNT = 20
local FRAME_SPEED = 8 -- frames between frame changes
local OBJECT_X = -200000
local OBJECT_Y = -200300 -- top left corner of object in scene space
local OBJECT_RENDERPRIORITY = -75 -- standard bgo priority
local currentFrame = -1
function onEvent(eventname)
if eventname == "EVENT_THAT_SHOULD_SHOW_THE_OBJECT" then
currentFrame = 0
end
end
-- probably don't need to edit below here
local frameTimer = 0
function onTickEnd()
if currentFrame >= 0 then
frameTImer = frameTimer + 1
if frameTimer == FRAME_SPEED then
currentFrame = currentFrame + 1
frameTimer = 0
if currentFrame > FRAME_COUNT then
currentFrame = FRAME_COUNT -- CHANGE THIS TO -1 IF YOU WANT IT TO BE HIDDEN AFTER REACHING THE END OF THE ANIMATION
end
end
end
end
function onDraw()
if currentFrame >= 0 then
Graphics.drawImageToSceneWP(OBJECT_IMAGE, OBJECT_X, OBJECT_Y, 0, currentFrame * (OBJECT_IMAGE.height / FRAME_COUNT), OBJECT_IMAGE.width, OBJECT_IMAGE.height / FRAME_COUNT, OBJECT_RENDERPRIORITY)
end
end
This draws an image in onDraw with the frame set based on a timer set in onTickEnd.
I'm sorry but I'm not very familiar with LUA script, where exactly would I use this? In a .lua file?
Added in 19 minutes 38 seconds:
So far it's not working, though I could be implementing the script wrong. I've changed a couple things to fit in the level, here is the edited script:
local OBJECT_IMAGE = Graphics.loadImage("background-123.png")
local FRAME_COUNT = 10
local FRAME_SPEED = 6
local OBJECT_X = -79552
local OBJECT_Y = -80352
local OBJECT_RENDERPRIORITY = 100
local currentFrame = -1
function onEvent(topplestart)
if eventname == "topplestart" then
currentFrame = 0
end
end
-- probably don't need to edit below here
local frameTimer = 0
function onTickEnd()
if currentFrame >= 0 then
frameTimer = frameTimer + 1
if frameTimer == FRAME_SPEED then
currentFrame = currentFrame + 1
frameTimer = 0
if currentFrame > FRAME_COUNT then
currentFrame = FRAME_COUNT -- CHANGE THIS TO -1 IF YOU WANT IT TO BE HIDDEN AFTER REACHING THE END OF THE ANIMATION
end
end
end
end
function onDraw()
if currentFrame >= 0 then
Graphics.drawImageToSceneWP(OBJECT_IMAGE, OBJECT_X, OBJECT_Y, 0, currentFrame * (OBJECT_IMAGE.height / FRAME_COUNT), OBJECT_IMAGE.width, OBJECT_IMAGE.height / FRAME_COUNT, OBJECT_RENDERPRIORITY)
end
end
Ideally, this would start the BGOs animation when an event called "topplestart" is run. I set the BGOs X/Y coordinates to what they are ingame, and I think there was a typo in the line "frameTimer = frameTimer + 1" (it said frameTImer the first time). Also, like I asked earlier, where exactly do I put this script in regards to my level? In a simple .lua file, or the "your code here" in the template leval luna file?