fix(actors/gfx): make gfx work

This commit is contained in:
Kazhnuz 2024-10-30 23:03:25 +01:00
parent a88fb44f07
commit 9ad1e5c4f1
3 changed files with 17 additions and 11 deletions

View file

@ -25,17 +25,15 @@ local GFX = extend("framework.scenes.world.actors")
local physics = require "framework.scenes.world.actors.physics.utils"
function GFX:new(world, position, spritename, is3D)
local width, height = world.scene.animators:get(spritename):getDimensions()
function GFX:new(world, position, spritename, is3D, useMiddle)
local width, height = world.animators:get(spritename):getDimensions()
local dimensions
if (is3D) then
dimensions = {w = width, h = height, d = 1}
else
dimensions = {w = width, h = width, d = height}
else
dimensions = {w = width, h = height, d = 1}
end
local dimVector = physics.dimensionsToVector(dimensions)
-- !HACK!
-- Cheat by creating at runtime the definition
@ -51,9 +49,12 @@ function GFX:new(world, position, spritename, is3D)
}
}
GFX.super.new(self, world, position + (dimVector / 2))
self:setSprite(spritename, true)
self.sprite:activateCallbacks()
if (useMiddle) then
local dimVector = physics.dimensionsToVector(dimensions)
position = position + (dimVector / 2)
end
GFX.super.new(self, world, position)
end
function GFX:animationEnded(animation)

View file

@ -56,6 +56,7 @@ end
function Actor:updateActor(dt)
self.timers:update(dt)
self:update(dt)
self:_updateVisual(dt)
self:applyMovement(dt)
end

View file

@ -34,6 +34,8 @@ local Camera = require("framework.scenes.world.camera.minimal")
local Vector3D = require "framework.libs.brinevector3D"
local GFX = require "framework.scenes.world.actors.gfx"
local function _tryFunction(toUpdate, dt, func)
if (toUpdate ~= nil) then
func(dt)
@ -148,8 +150,6 @@ function World:_initActorList(actorPath)
self.obj = {}
self:_indexActors()
self:_prepareActorObject("gfx")
end
function World:_prepareActorObject(name)
@ -214,6 +214,10 @@ function World:newActor(name, x, y, z, properties, mapname)
return self:addActor(name, { x = x, y = y, z = z })
end
function World:showGFX(effect, position, useMiddle)
table.insert(self.actors, GFX(self, position, effect, false, (useMiddle == true)))
end
function World:addActor(name, position)
local Actor = self:_getActorObject(name)
if (name == "player") then