hi,
I've been considering using love for my 1st foray into game making. I would like to have a player sprite in the centre of the screen and have the background rotate under the player as well as move up and down, so that the player appears fixed pointing towards the top of the screen.
Conceptually, would this be achieved by rotating and moving both the player image and the camera simultaneously to make the illusion of a fixed player position on screen?
thanks for any help.
rotate camera with player?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Sheepolution
- Party member
- Posts: 264
- Joined: Mon Mar 04, 2013 9:31 am
- Location: The Netherlands
- Contact:
Re: rotate camera with player?
I think it's simply love.graphics.rotate( -player_rotation )
If you rotate the player with +5, and rotate the camera back with -5, the player's rotation comes back to 0.
If you rotate the player with +5, and rotate the camera back with -5, the player's rotation comes back to 0.
- kikito
- Inner party member
- Posts: 3153
- Joined: Sat Oct 03, 2009 5:22 pm
- Location: Madrid, Spain
- Contact:
Re: rotate camera with player?
It's not that simple, I am afraid. Keeping the player in the center of the screen is somewhat difficult if you are rotating things around. Moreso if you are also zooming in and out at the same time.
I made a library whose purpose is making these calculations so you don't have to. It's called gamera.
This is how the code could look (adapt the player functions to whatever you use):
I made a library whose purpose is making these calculations so you don't have to. It's called gamera.
This is how the code could look (adapt the player functions to whatever you use):
Code: Select all
local gamera = require 'gamera'
local cam = gamera.new(0,0, 4000,4000) -- world size
...
local player = ... -- create the player
...
function love.update(dt)
updatePlayer(player, dt)
cam:setPosition(getPlayerPosition(player))
cam:setAngle(getPlayerAngle(player))
cam:setScale(...) -- zoom in/out
end
function love.draw()
cam:draw(function()
drawPlayer(player)
... -- draw everything that needs to be rotated/zoomed here
end)
drawScore()
drawLivesLeft()
end
When I write def I mean function.
Re: rotate camera with player?
thanks very much for the replies. I'll take a look at gamera and see how it goes
-
- Prole
- Posts: 19
- Joined: Sat Sep 06, 2014 8:50 pm
Re: rotate camera with player?
Kikito, I've implemented your camera system, and it's incredibly valuable. The only thing I can't seem to get working is finding mouse coordinates.
How do I find the mouse location with this system?
EDIT: figured it out. I had my understanding of cam:toWorld() and cam:toScreen() backwards. I was using toScreen when I should have been using toWorld. Thanks again for the phenomenal system.
Also, a minor note, it wouldnt let "local gamera = {}" pass the compiler. I had to change it to a global variable.
How do I find the mouse location with this system?
EDIT: figured it out. I had my understanding of cam:toWorld() and cam:toScreen() backwards. I was using toScreen when I should have been using toWorld. Thanks again for the phenomenal system.
Also, a minor note, it wouldnt let "local gamera = {}" pass the compiler. I had to change it to a global variable.
Who is online
Users browsing this forum: Ahrefs [Bot] and 16 guests