Last active
October 26, 2018 19:30
-
-
Save NoahRoseLedesma/85ebea555cd4811623457ba3993920ea to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- When running this code in LOVE, the player's top left corner dot and square will follow the top left corner of the white square | |
-- When running this code on hardware with LovePotion for switch, the dot will not follow the top left corner of the white square, but the square will | |
camera = {} | |
camera._x = 0 | |
camera._y = 0 | |
function camera:set() | |
love.graphics.push() | |
love.graphics.translate(-self._x, -self._y) | |
end | |
function camera:unset() | |
love.graphics.pop() | |
end | |
function love.load() | |
width = love.graphics.getWidth() | |
height = love.graphics.getHeight() | |
player = { | |
x = 0, | |
y = 0, | |
width = 50, | |
height = 50, | |
speed = 300, | |
color = { 150, 150, 150 } | |
} | |
end | |
function love.update(dt) | |
player.x = player.x + 5 | |
player.y = player.y + 5 | |
camera._x = player.x - width / 2 | |
camera._y = player.y - height / 2 | |
end | |
function love.draw() | |
camera:set() | |
-- player | |
love.graphics.setColor(player.color) | |
love.graphics.rectangle('fill', player.x, player.y, player.width, player.height) | |
-- player top left corner | |
love.graphics.setColor(0, 0.6, 0, 1) | |
love.graphics.circle('fill', player.x - 3, player.y - 3, 6) | |
love.graphics.rectangle('fill', player.x + 4, player.y + 4, 4, 4) | |
camera:unset() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment