Camera (gamera) does not update

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
IgnorantPeasant
Prole
Posts: 6
Joined: Tue Sep 25, 2018 8:05 am

Camera (gamera) does not update

Post by IgnorantPeasant »

Yo guys, I just started a couple hours ago, have experience in programming but not with LUA or this engine. Getting things done pretty fast tho.

So I just created an isometric map and added this camera
https://github.com/kikito/gamera

I can zoom in and out but I can't make it move, can't figure what I am doing wrong.

Code: Select all

local gamera = require 'gamera'
local zoom = false
camera_x = 0
camera_y = 0
cam = gamera.new(camera_x,camera_y,1920,1080)

grid_size = 6
screen_width = love.graphics.getWidth()
screen_height = love.graphics.getHeight()	
grid_x = (screen_width / 2)
grid_y =  (screen_height / 2)

grass = love.graphics.newImage( "grass.png" )
dirt = love.graphics.newImage( "dirt.png" )


block_width = grass:getWidth()
block_height = grass:getHeight()
block_depth = block_height

grid = {}
for x = 1,grid_size do
   grid[x] = {}
   for y = 1,grid_size do
      grid[x][y] = 1
   end
end

grid[2][4] = 2
grid[6][5] = 2

local last_input = "none"

function love.load()
  love.window.setMode(0, 0, {fullscreen = true})
end

function love.keypressed(key)
   if key == "escape" then
   		love.event.quit()
	elseif key == "left" then	  
		last_input = "left"
		camera_x = camera_x  - 10
	elseif key == "right" then
		last_input = "right"
		camera_x = camera_x  + 10
	elseif key == "up" then		
		last_input = "up"
		camera_y = camera_y - 10	
	elseif key == "down" then		
		last_input = "down"
		camera_y = camera_y + 10		
	end
end

function love.wheelmoved(x, y)
    if y > 0 then
       zoom = true
    elseif y < 0 then
        zoom = false
    end
end

function love.update(dt)
	cam:setPosition(camera_x, camera_y)
end

function love.draw() 
	if zoom then
		cam:setScale(2.0) 
	else
		cam:setScale(1.0) 
	end

	for x = 1,grid_size do
		for y = 1,grid_size do
	    		if grid[x][y] == 1 then
				cam:draw(function(l,t,w,h)		  
	         		love.graphics.draw(grass, grid_x + ((y-x) * (block_width / 2)), grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2)))  end)				
	      else -- grid[x][y] == 2
			cam:draw(function(l,t,w,h)		  		  
	        	love.graphics.draw(dirt, grid_x + ((y-x) * (block_width / 2)), grid_y + ((x+y) * (block_depth / 2)) - (block_depth * (grid_size / 2))) end)								
	      end
	   end
	end
	love.graphics.print(screen_width .. "x" .. screen_height, 1800, 900)
	love.graphics.print("Last pressed key: " .. last_input, 1720, 950)
	love.graphics.print("camera: " .. camera_x .. " " .. camera_y, 1800, 1000)
	love.graphics.print("camera feedback: " .. cam:getPosition(), 1700, 1040)
end
   
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Camera (gamera) does not update

Post by bobbyjones »

The camera only moves if it has space to do so. You have to enlarge the boundaries in the definition to the world size.

Code: Select all

cam = gamera.new(camera_x,camera_y,1920,1080) -- change the last two diminsions to the world size. 
--and set the first 2 to the origin of the world. 

cam:setWindow(l,h) --defines the viewport of the camera. this would be 
--the window size or smaller if its a minimap.
IgnorantPeasant
Prole
Posts: 6
Joined: Tue Sep 25, 2018 8:05 am

Re: Camera (gamera) does not update

Post by IgnorantPeasant »

Thank you, that makes sense.
However I increased world size

Code: Select all

gamera.new(camera_x,camera_y,3000,2000)
...and still doesn't move

Also getPosition() and getVisible() always return the same values (960 and 0 respectively) regardless camera_x and camera_y are being modified.
IgnorantPeasant
Prole
Posts: 6
Joined: Tue Sep 25, 2018 8:05 am

Re: Camera (gamera) does not update

Post by IgnorantPeasant »

it seems it start moving in the x axis when camera_x reach the screen width or half at 1.0 scale, also it doesn't move to the left.
I must bee just too dumb because I can't figure why.
bobbyjones
Party member
Posts: 730
Joined: Sat Apr 26, 2014 7:46 pm

Re: Camera (gamera) does not update

Post by bobbyjones »

The camera starts at 0,0 and is bound to a minimum of 0,0 so you can't move left or up (I think y points down. I haven't used love in awhile.)
IgnorantPeasant
Prole
Posts: 6
Joined: Tue Sep 25, 2018 8:05 am

Re: Camera (gamera) does not update

Post by IgnorantPeasant »

I understand but camera is at 960 and it refuses to move to the left (5760 width world)
grump
Party member
Posts: 947
Joined: Sat Jul 22, 2017 7:43 pm

Re: Camera (gamera) does not update

Post by grump »

IgnorantPeasant wrote: Wed Sep 26, 2018 10:41 am I understand but camera is at 960 and it refuses to move to the left (5760 width world)
If viewport width is 1920, midpoint of the camera is at x=960 and your world starts at x=0, then there is no more room for the camera to move on the left side (midpoint - half viewport width = 0).

I don't use gamera, so I don't know if it's possible, but the obvious solution is to let your world start at x=-2880.
IgnorantPeasant
Prole
Posts: 6
Joined: Tue Sep 25, 2018 8:05 am

Re: Camera (gamera) does not update

Post by IgnorantPeasant »

Regardless its position the camera only moves 1920 pixels over the X axis.
Considering I have a 1920p width screen and the world is set 3 times that value it should move 3840 at least, so I don't know.
I'll try a different one, suggestions are welcome!
IgnorantPeasant
Prole
Posts: 6
Joined: Tue Sep 25, 2018 8:05 am

Re: Camera (gamera) does not update

Post by IgnorantPeasant »

I just coded my own, thanks everyone for your answers.

SOLVED
User avatar
yetneverdone
Party member
Posts: 446
Joined: Sat Sep 24, 2016 11:20 am
Contact:

Re: Camera (gamera) does not update

Post by yetneverdone »

I also face this problem. It seems that restriction ofna camera has its dowsides
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 57 guests