Page 1 of 1

[Solved!] Cursor movement problem

Posted: Tue Dec 11, 2012 5:34 am
by bramblez
Check last post.

Hello there, dear friends! :)
I am trying to make a sort of a top-down shooter game. Just opened a world of libraries to myself ^^ so I am not very experienced.
Right now I am facing a silly problem, really.
I've made a player-character and basic shooting ability, but when I added a simple camera lib - I could not seem to get a cursor moving outside of the default screen window. I mean it is moving, but when you move character somewhere - cursor can't get outside of the starting area.
Here is the .love file for you! :)

Re: Cursor movement problem

Posted: Tue Dec 11, 2012 6:47 am
by Robin
The problem is not in the camera lib: it is in your menu.lua. Remove line 13, the one that says love.mouse.setGrab(true) and you can move your cursor away from the window.

Re: Cursor movement problem

Posted: Tue Dec 11, 2012 8:01 am
by bramblez
No it's not that, cursor is limited by first frame of the window, i can't move cursor image when my character runs away outside first frame.
download my .love file and try to run with character below the screen and you will see what i mean ;)

Re: Cursor movement problem

Posted: Tue Dec 11, 2012 8:14 am
by Robin
Oh, that. Change line 9 and 10 in menu.lua to

Code: Select all

	local mousex = love.mouse.getX() + camera.x
	local mousey = love.mouse.getY() + camera.y
(You still do setgrab every frame, you can move that call to love.load()).

Re: [Solved] Cursor movement problem

Posted: Tue Dec 11, 2012 8:37 am
by bramblez
Thank you very much! works like a charm ;)

Re: [new issue] Cursor movement problem

Posted: Wed Dec 12, 2012 7:00 am
by bramblez
New problem! :)
It's really hard for me to explain, you pretty much will be able to see the problem once you launch the .love file.
the thing is, i need to add smooth camera movement, but limit it by ~25 from character. so that you could look further with your mouse, but not too far from character at the same time.
it works atm, but value is fixated at 25, so it jumps to those values when "If" is true, i need it to be smooth. I know that i have to use dt, but everything i've tryed seemed not to work

Re: [new issue] Cursor movement problem

Posted: Wed Dec 12, 2012 9:30 am
by bramblez
I got this all wrong, in the result I need camera to move in a small circle around character, depending on cursor position. If that makes any sense

Re: [new issue] Cursor movement problem

Posted: Wed Dec 12, 2012 10:33 am
by bramblez
I managed to twicked something out. it looks better, but center of camera rotation is at the begining of coordinate system.

Re: [new issue] Cursor movement problem

Posted: Wed Dec 12, 2012 10:48 am
by Santos
I drew this out on paper a bit, and came up with this.

What is basically does is set the camera position to the player position, but with an offset, which is affected by the how close the mouse is to the player, and clamped between a maximum and minimum value.

Code: Select all

function camera_update()
	local easing = 10
	local max_offset = 25 * easing

	local offset_x = math.max(math.min(mousexe - player.x + camera.x, max_offset), -max_offset) / easing
	local offset_y = math.max(math.min(mouseye - player.y + camera.y, max_offset), -max_offset) / easing

	camera.x = player.x - (screenWidth / 2) + offset_x
	camera.y = player.y - (screenHeight / 2) + offset_y
end
And it's called from love.update:

Code: Select all

function love.update(dt)

	mousexe = love.mouse.getX()
	mouseye = love.mouse.getY()

	player_update(dt)
	bullets_update(dt)

	camera_update()
	
end

Re: [new issue] Cursor movement problem

Posted: Wed Dec 12, 2012 10:53 am
by bramblez
Thank you, that is what i was looking for! ^^ :awesome: