i love easing4d
Co-authored-by: Ivan Yuriev <ivanyr44@gmail.com>
This commit is contained in:
parent
cdffff59c3
commit
331aefb0f6
@ -9,6 +9,9 @@ local EPSILON = 0.001
|
|||||||
--- @field speed number
|
--- @field speed number
|
||||||
--- @field pixelsPerMeter integer
|
--- @field pixelsPerMeter integer
|
||||||
--- @field scale number
|
--- @field scale number
|
||||||
|
--- @field animationNode AnimationNode?
|
||||||
|
--- @field animationEndPosition Vec3
|
||||||
|
--- @field animationBeginPosition Vec3
|
||||||
local camera = {
|
local camera = {
|
||||||
position = Vec3 {},
|
position = Vec3 {},
|
||||||
velocity = Vec3 {},
|
velocity = Vec3 {},
|
||||||
@ -41,6 +44,12 @@ local controlMap = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function camera:update(dt)
|
function camera:update(dt)
|
||||||
|
if self.animationNode and not (self.animationNode.t >= 1) then
|
||||||
|
self.animationNode:update(dt) -- тик анимации
|
||||||
|
self.position = utils.lerp(self.animationBeginPosition, self.animationEndPosition, self.animationNode:getValue())
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local ps = Tree.panning
|
local ps = Tree.panning
|
||||||
if ps.delta:length() > 0 then
|
if ps.delta:length() > 0 then
|
||||||
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
|
local worldDelta = ps.delta:scale(1 / (self.pixelsPerMeter * self.scale)):scale(dt):scale(self.speed)
|
||||||
@ -88,8 +97,12 @@ function camera:detach()
|
|||||||
end
|
end
|
||||||
|
|
||||||
--- @param position Vec3
|
--- @param position Vec3
|
||||||
function camera:animateTo(position)
|
--- @param animationNode AnimationNode
|
||||||
self.position = position
|
function camera:animateTo(position, animationNode)
|
||||||
|
if self.animationNode then self.animationNode:finish() end
|
||||||
|
self.animationNode = animationNode
|
||||||
|
self.animationEndPosition = position
|
||||||
|
self.animationBeginPosition = self.position
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @return Camera
|
--- @return Camera
|
||||||
|
|||||||
8
main.lua
8
main.lua
@ -40,11 +40,15 @@ function love.update(dt)
|
|||||||
Tree.level.turnOrder:toggleTurns()
|
Tree.level.turnOrder:toggleTurns()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- для тестов camera:attachTo
|
-- для тестов camera:animateTo
|
||||||
-- удалить как только потребность в тестах исчезнет
|
-- удалить как только потребность в тестах исчезнет
|
||||||
if Tree.controls:isJustPressed("cameraAnimateTo") then
|
if Tree.controls:isJustPressed("cameraAnimateTo") then
|
||||||
local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() })
|
local mousePosition = Tree.level.camera:toWorldPosition(Vec3 { love.mouse.getX(), love.mouse.getY() })
|
||||||
Tree.level.camera:animateTo(mousePosition)
|
require('lib.animation_node') {
|
||||||
|
function(animationNode) Tree.level.camera:animateTo(mousePosition, animationNode) end,
|
||||||
|
onEnd = function() print('completed') end,
|
||||||
|
easing = require("lib.utils.easing").easeInOutCubic
|
||||||
|
}:run()
|
||||||
end
|
end
|
||||||
|
|
||||||
Tree.controls:cache()
|
Tree.controls:cache()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user