I have a problem with my tweening. I am using tween.lua to move my character left or right when that button is held. On release the player returns back to the middle. Tweening works perfectly for when the character goes either left or right but, for some reason when it has to go back to the middle the character just warps there and does not tween. I suspect that either the base X is overriding it or I am not resseting at the right moment. Here is my code:
--Local variables
local lg = love.graphics
local lk = love.keyboard
function player:load(arg) --Player load function. Called when loaded.
self.img = lg.newImage(currentPimg)
playerWidth = player.img:getWidth() --Gets player image width and sets as a variable
self.mid = width/2 - playerWidth/2
self.left = 100 - playerWidth/2
self.right = width - 100 - playerWidth/2
self.x = player.mid
self.y = height-150
self.speed = 0.04
GoMid = tween.new(player.speed , player, {x=player.mid}, 'linear')
GoLeft = tween.new(player.speed , player, {x=player.left}, 'linear')
GoRight = tween.new(player.speed , player, {x=player.right}, 'linear')
end
function player:update(dt) --Player update function. Called each frame, passes DT (delta time)
playerWidth = player.img:getWidth() --Gets player image width and sets as a variable
if LeftStarted and not isLeft then
GoLeft:reset()
LeftStarted = false
end
if RightStarted and not isRight then
GoRight:reset()
RightStarted = false
end
if MidStarted and not isMid then
GoMid:reset()
MidStarted = false
end
if isMid then --If is true then do action
GoMid:update(dt)
MidStarted = true
end
if isRight then --If is true then do action
GoRight:update(dt)
RightStarted = true
end
if isLeft then --If is true then do action
GoLeft:update(dt)
LeftStarted = true
end
if lk.isDown("left", "a") and not isRight then --this check needs to be done since the code is executed the first time. If I do not check weird stuff happens
isLeft = true
isRight, isMid = false
elseif lk.isDown("right", "d") then --checks if the button is down and returns true if it is
isRight = true
isLeft, isMid = false
else -- if nothing is down resets player to mid and all variables to false
isLeft, isRight = false
isMid = true
end
end
function player:draw(dt) --Draw function. Called each frame, passes DT (delta time)
lg.draw(player.img, player.x, player.y) --Draws player image at X and Y
end