Page 1 of 1

Question:How to display miltiple images in different timing

Posted: Sat Jul 25, 2009 1:29 pm
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 :)

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

Posted: Sat Jul 25, 2009 2:01 pm
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.

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

Posted: Sun Jul 26, 2009 3:21 pm
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:

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

Posted: Sun Jul 26, 2009 3:23 pm
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.