[Solved!] Cursor movement problem

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
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

[Solved!] Cursor movement problem

Post 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! :)
Attachments
Haidewalk.love
(89.04 KiB) Downloaded 180 times
Last edited by bramblez on Wed Dec 12, 2012 10:54 am, edited 4 times in total.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Cursor movement problem

Post 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.
Help us help you: attach a .love.
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

Re: Cursor movement problem

Post 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 ;)
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Cursor movement problem

Post 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()).
Help us help you: attach a .love.
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

Re: [Solved] Cursor movement problem

Post by bramblez »

Thank you very much! works like a charm ;)
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

Re: [new issue] Cursor movement problem

Post 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
Attachments
haidewalk(0.0.3).love
(90.12 KiB) Downloaded 180 times
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

Re: [new issue] Cursor movement problem

Post 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
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

Re: [new issue] Cursor movement problem

Post by bramblez »

I managed to twicked something out. it looks better, but center of camera rotation is at the begining of coordinate system.
Attachments
haidewalk(two).love
(90.41 KiB) Downloaded 369 times
Santos
Party member
Posts: 384
Joined: Sat Oct 22, 2011 7:37 am

Re: [new issue] Cursor movement problem

Post 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
User avatar
bramblez
Citizen
Posts: 50
Joined: Sun Jul 29, 2012 1:21 pm
Location: Russia, Moscow

Re: [new issue] Cursor movement problem

Post by bramblez »

Thank you, that is what i was looking for! ^^ :awesome:
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests