Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --customblockanim.lua by Enjl
- --simple block animation helper to make multi-frame blocks easier as per version SMBX2bmx3
- --ver 1.0
- local cba = {}
- local blocks = {}
- local stock0 = Graphics.loadImage(Misc.resolveFile("graphics/stock-0.png"))
- local deferred = {}
- local firstFrame = true
- local function registerBlock(id, args)
- args = args or {}
- if id == nil then
- error("ID must be specified when registering new block animation.")
- return
- end
- local image = args.image
- if image == nil then
- image = Graphics.sprites.block[id].img
- Graphics.sprites.block[id].img = stock0
- end
- local frames = args.frames or 4
- local framespeed = args.framespeed or 8
- local opacity = args.opacity or 1
- local priority = args.priority or -65
- local w = image.width
- local h = image.height / frames
- blocks[id] = {f = frames, fs = framespeed, img = image, w = w, h = h, o = opacity, p = priority}
- for k,v in ipairs(Block.get(id)) do
- v.width = w
- v.height = h
- end
- end
- -- Call this. ID is mandatory, args are:
- ---frames
- ---framespeed
- ---opacity
- ---priority
- ---image
- function cba.register(id, args)
- if firstFrame then
- table.insert(deferred, {id = id, args = args})
- else
- registerBlock(id, args)
- end
- end
- function cba.onInitAPI()
- registerEvent(cba, "onCameraDraw")
- registerEvent(cba, "onStart")
- end
- local timer = 0
- function cba.onStart()
- for k,v in ipairs(deferred) do
- registerBlock(v.id, v.args)
- end
- end
- function cba.onCameraDraw()
- timer = timer + 1
- for k,v in ipairs(Block.getIntersecting(camera.x, camera.y, camera.x + camera.width, camera.y + camera.height)) do
- if blocks[v.id] then
- if (not v.isHidden) and v:mem(0x5A, FIELD_WORD) == 0 then
- local bv = blocks[v.id]
- Graphics.drawImageToSceneWP(bv.img, v.x, v.y + v:mem(0x56, FIELD_WORD), 0, bv.h * (math.floor(timer/bv.fs)%bv.f), bv.w, bv.h, bv.o, bv.p)
- end
- end
- end
- end
- return cba
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement