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!
[Solved!] Cursor movement problem
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
[Solved!] Cursor movement problem
- 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.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Cursor movement problem
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.
Re: Cursor movement problem
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
download my .love file and try to run with character below the screen and you will see what i mean
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Cursor movement problem
Oh, that. Change line 9 and 10 in menu.lua to
(You still do setgrab every frame, you can move that call to love.load()).
Code: Select all
local mousex = love.mouse.getX() + camera.x
local mousey = love.mouse.getY() + camera.y
Help us help you: attach a .love.
Re: [new issue] Cursor movement problem
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
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
Re: [new issue] Cursor movement problem
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
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
Re: [new issue] Cursor movement problem
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.
And it's called from love.update:
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
Code: Select all
function love.update(dt)
mousexe = love.mouse.getX()
mouseye = love.mouse.getY()
player_update(dt)
bullets_update(dt)
camera_update()
end
Who is online
Users browsing this forum: Bing [Bot] and 2 guests