Question:How to display miltiple images in different timing

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
rrickie
Prole
Posts: 2
Joined: Thu Jul 23, 2009 2:35 pm

Question:How to display miltiple images in different timing

Post by rrickie »

Hello everyone, i am new in LOVE, thanks for the team to create this great engine, it's really awesome!!

However i have a question about the multiple images drawing at different timing, the following is the situation that i am trying to achieve:
- The time line order is A to B to C to D
- During time A to B, draw image1 and image2
- During time B to C, draw image1, image2, image3 and image4
- During time C to D, draw image3 and image4

But the result i got is that the game draws imageA and imageC until time reaches C, then starts to draw imageB and imageD until time reaches D.

The following is the lua scripting:

Code: Select all

function draw()
    if elapsed >= 1.0 and elapsed <= 10.0 then
        love.graphics.draw(image1, 100, 100)
        love.graphics.draw(image2, 200, 100)
    elseif elapsed >= 6.0 and elapsed <= 12.0 then
        love.graphics.draw(image3, 300, 100)
        love.graphics.draw(image4, 400, 100)
    end
end
I am new in LOVE and Lua, there are so many things that I am not falimiar with, Can anyone help me with it? Thank you soooooo much :)
User avatar
Tenoch
Citizen
Posts: 76
Joined: Mon Jul 21, 2008 7:49 am

Re: Question:How to display miltiple images in different timing

Post by Tenoch »

Mmm the two cases don't exclude each other. Replace the elseif by another if (and don't forget to close both if's with "end"). It should do the trick.
"When in doubt, use brute force." Ken Thompson
rrickie
Prole
Posts: 2
Joined: Thu Jul 23, 2009 2:35 pm

Re: Question:How to display miltiple images in different timing

Post by rrickie »

Thank you soooo much Tenoch :), it works!!!!!!!
By using what you mentioned, now i can draw multiple images, so cooooool, thank you again :rofl:
User avatar
Schoon
Prole
Posts: 3
Joined: Sun Jul 19, 2009 10:41 pm
Location: Maynard, MA
Contact:

Re: Question:How to display miltiple images in different timing

Post by Schoon »

Alternatively, if you really want to think of it as three distinct time periods: AB, BC, and CD, then do this:

Code: Select all

function draw()
    if elapsed >= 1.0 and elapsed < 6.0 then
        love.graphics.draw(image1, 100, 100)
        love.graphics.draw(image2, 200, 100)
    elseif elapsed >= 6.0 and elapsed < 10.0 then
        love.graphics.draw(image1, 100, 100)
        love.graphics.draw(image2, 200, 100)
        love.graphics.draw(image3, 300, 100)
        love.graphics.draw(image4, 400, 100)
    elseif elapsed >= 10.0 and elapsed <= 12.0 then
        love.graphics.draw(image3, 300, 100)
        love.graphics.draw(image4, 400, 100)
    end
end
However, Tenoch's suggestion will make for cleaner code. All depends on how you want to structure things.
Post Reply

Who is online

Users browsing this forum: No registered users and 3 guests