Hey Guys! I have recently been having troubles in my script (as in it has been taking too much space). So my problem is when i want to play an animation i use a method of teleporting the animation or sprite to the previous x and y. for example...
require("AnAL")
love.graphics.setBackgroundColor(255,255,255)
health = 5
y5 = -600
y4 = -600
y3 = -600
y2 = -600
y1 = -600
y0 = -600
function love.load()
health5 = love.graphics.newImage("assets/heartline5.png")
health4 = love.graphics.newImage("assets/heartline4.png")
health3 = love.graphics.newImage("assets/heartline3.png")
health2 = love.graphics.newImage("assets/heartline2.png")
health1 = love.graphics.newImage("assets/heartline1.png")
health0 = love.graphics.newImage("assets/heartline0.png")
end
function love.update(dt)
--health
if health == 5 then
y5 = 20
y4 = -600
y3 = -600
y2 = -600
y1 = -600
y0 = -600
elseif health == 4 then
y5 = -600
y4 = 20
y3 = -600
y2 = -600
y1 = -600
y0 = -600
elseif health == 3 then
y5 = -600
y4 = -600
y3 = 20
y2 = -600
y1 = -600
y0 = -600
elseif health == 2 then
y5 = -600
y4 = -600
y3 = -600
y2 = 20
y1 = -600
y0 = -600
elseif health == 1 then
y5 = -600
y4 = -600
y3 = -600
y2 = -600
y1 = 20
y0 = -600
elseif health == 0 then
y5 = -600
y4 = -600
y3 = -600
y2 = -600
y1 = -600
y0 = 20
end
--health
end
function love.draw()
love.graphics.draw(health5, 800, y5)
love.graphics.draw(health4, 800, y4)
love.graphics.draw(health3, 800, y3)
love.graphics.draw(health2, 800, y2)
love.graphics.draw(health1, 800, y1)
love.graphics.draw(health0, 800, y0)
end
So my question is, is there a quicker and more efficient way of doing this, like "undrawing" the image or animation and then recalling it? instead of just teleporting it off screen? this would make my scripts much more efficient and easier to navigate
local health
love.load()
health = {}
-- even this could be written with less duplication as a cycle (a for loop)
health[0] = love.graphics.newImage("assets/heartline0.png")
health[1] = love.graphics.newImage("assets/heartline1.png")
health[2] = love.graphics.newImage("assets/heartline2.png")
health[3] = love.graphics.newImage("assets/heartline3.png")
health[4] = love.graphics.newImage("assets/heartline4.png")
health[5] = love.graphics.newImage("assets/heartline5.png")
end
local timer = 0.0
local frame = 0
function love.update(dt)
timer = timer + dt
if timer >= 1.0 then
frame = (frame + 1) % 6 -- or use a variable, like totalFrames or something
timer = timer - 1.0
end
end
function love.draw()
love.graphics.draw(health[frame], 800, 20)
end
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
local health
love.load()
health = {}
-- even this could be written with less duplication as a cycle (a for loop)
health[0] = love.graphics.newImage("assets/heartline0.png")
health[1] = love.graphics.newImage("assets/heartline1.png")
health[2] = love.graphics.newImage("assets/heartline2.png")
health[3] = love.graphics.newImage("assets/heartline3.png")
health[4] = love.graphics.newImage("assets/heartline4.png")
health[5] = love.graphics.newImage("assets/heartline5.png")
end
local timer = 0.0
local frame = 0
function love.update(dt)
timer = timer + dt
if timer >= 1.0 then
frame = (frame + 1) % 6 -- or use a variable, like totalFrames or something
timer = timer - 1.0
end
end
function love.draw()
love.graphics.draw(health[frame], 800, 20)
end
haii again!, Thanks for the code, just wondering with this code ,will it delete the picture after use (as in another one is called)
Don't mean to offend, but you don't need advanced tutorials showing techniques, you need a beginner's Lua tutorial.
Take a look at the free "Programming in Lua" guide!
Last edited by s-ol on Thu Jan 07, 2016 4:20 pm, edited 1 time in total.
Buby wrote:haii again!, Thanks for the code, just wondering with this code ,will it delete the picture after use (as in another one is called)
If you mean will it only show one image at once, then yes.
If you mean will it unload all the other images, then no, but since you're gonna animate using them, why load and unload them all the time? That's slow and unnecessary.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
S0lll0s wrote:Don't mean to offend, but you don't need advanced tutorials showing techniques, you need a beginner's Lua tutorial.
Take a look at the free "Programming in Lua" guide!
I agree with you on some terms but i do know the basics and was looking for how to improve on my techniques maybe i just worded it wrong
Buby wrote:haii again!, Thanks for the code, just wondering with this code ,will it delete the picture after use (as in another one is called)
If you mean will it only show one image at once, then yes.
If you mean will it unload all the other images, then no, but since you're gonna animate using them, why load and unload them all the time? That's slow and unnecessary.
oh okay i get it now, ive always wondered how to use tables, I will try to learn more about them
S0lll0s wrote:Don't mean to offend, but you don't need advanced tutorials showing techniques, you need a beginner's Lua tutorial.
Take a look at the free "Programming in Lua" guide!
I agree with you on some terms but i do know the basics and was looking for how to improve on my techniques maybe i just worded it wrong
hello
Tables are very useful in lua. If you learn more about them, your programming power will increase 100x