Display whole map at end of game

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
RamblinLane
Prole
Posts: 4
Joined: Fri Jun 03, 2022 11:42 am

Display whole map at end of game

Post by RamblinLane »

Hi

I followed the Callacades tutorial on Love2d Basics (https://youtube.com/playlist?list=PLqPL ... _h_JGLgGg2)

I added some coins to collect and each disappear as collected.

At the end of the game I want to zoom out to show the whole map.

Map is created in Tiled with 2 Layers

gameMap is loaded with STI
Windfield for the world
Camera to track the player

love.draw displays portion of map with

Code: Select all

function love.draw()
    cam:attach()
        if gameOver then
            gameMap:resize(screen.w, screen.h)
            gameMap:drawLayer(gameMap.layers["Ground"])
            gameMap:drawLayer(gameMap.layers["Trees"])
        else
            gameMap:drawLayer(gameMap.layers["Ground"])
            gameMap:drawLayer(gameMap.layers["Trees"])
            --coin.animation:draw(coin.spriteSheet, coin.x, coin.y, nil, .7, nil, 16, 13)
            for i, coin in pairs(coins)
            do
                coin.animation:draw(coin.spriteSheet, coin.x, coin.y, nil, .7, nil, 16, 13)
            end
            player.anim:draw(player.spriteSheet, player.x, player.y, nil, 6, nil, 6, 9)
            world:draw()
        end
    cam:detach()
end
if gameOver I want to zoom out and show the whole map on the screen

TIA
RamblinLane
Prole
Posts: 4
Joined: Fri Jun 03, 2022 11:42 am

Re: Display whole map at end of game

Post by RamblinLane »

Figured it out

Draw full screen outside the camera

still want to figure out how to centre the image

Code: Select all

function love.draw()
    if gameOver then
        love.graphics.scale( math.min(screen.h / screen.mapH, screen.w / screen.mapW ) )
        gameMap:drawLayer(gameMap.layers["Ground"])
        gameMap:drawLayer(gameMap.layers["Trees"])
    else
        cam:attach()
            gameMap:drawLayer(gameMap.layers["Ground"])
            gameMap:drawLayer(gameMap.layers["Trees"])

            for i, coin in pairs(coins)
            do
                coin.animation:draw(coin.spriteSheet, coin.x, coin.y, nil, .7, nil, 16, 13)
            end

            player.anim:draw(player.spriteSheet, player.x, player.y, nil, 6, nil, 6, 9)

            world:draw()
        cam:detach()
        love.graphics.print(tostring(player.x) .. ":" .. tostring(player.y))
    end
end
User avatar
milon
Party member
Posts: 472
Joined: Thu Jan 18, 2018 9:14 pm

Re: Display whole map at end of game

Post by milon »

Assuming you're drawing the image at 0,0 you would do something like this:

local image_w, image_h = image:getDimensions()
camera.x = math.floor((image_w - camera.w) / 2)
camera.y = math.floor((image_h - camera.h) / 2)

Then set your camera to camera.x, camera.y. This is assuming the camera uses coords for its top-left corner rather than its center or whatever. Obviously rename the variables to whatever you need them to be. FYI, the math.floor calls ensure you're dealing with integer co-ordinates, which helps images & text stay crisp and non-blurry.
Any code samples/ideas by me should be considered Public Domain (no attribution needed) license unless otherwise stated.
RamblinLane
Prole
Posts: 4
Joined: Fri Jun 03, 2022 11:42 am

Re: Display whole map at end of game

Post by RamblinLane »

Thanks milon will give it a try
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Vixii and 192 guests