Help developing a camera that moves with mouse
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Help developing a camera that moves with mouse
Hello, I am trying to make a scrolling like system. A bit like moving a window around on Windows. I tried to make one, but I always got results I didn't like. Can I see some code samples for something that does this? It would be very usefull.
Last edited by cemcmd on Sat Feb 18, 2017 12:12 am, edited 1 time in total.
- zorg
- Party member
- Posts: 3465
- Joined: Thu Dec 13, 2012 2:55 pm
- Location: Absurdistan, Hungary
- Contact:
Re: Help developing a scrolling like system
Moving windows around on the desktop is not scrolling; scrolling is when content is bigger than a window, for example, and you have to move the "camera" to see everything (whether by mouse or by scroll-bars or key input or whatever, doesn't matter).
So yeah, a bit more information would be nice, before we could help you.
So yeah, a bit more information would be nice, before we could help you.
Me and my stuff True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Re: Help developing a scrolling like system
Well I want to have the ability to move a camera around using the mouse.
-
- Party member
- Posts: 548
- Joined: Wed Oct 05, 2016 11:53 am
Re: Help developing a scrolling like system
Please specify further; how do you want to move the camera around with mouse inputs?
Move it when cursor touches the edges of the screen, move it when holding down a button and moving the cursor about ("panning" as it is called in plenty of programs), move the camera based on mouse strokes (like how a FPS game might do it), or something else?
Whatever the case may be, I recommend taking a look at love.graphics.translate for one way to do it. Basically just store the camera coordinates somehow, change them based on the desired inputs, and then inside love.draw:
Of course, you can always look into some libraries that provide camera functionality.
Move it when cursor touches the edges of the screen, move it when holding down a button and moving the cursor about ("panning" as it is called in plenty of programs), move the camera based on mouse strokes (like how a FPS game might do it), or something else?
Whatever the case may be, I recommend taking a look at love.graphics.translate for one way to do it. Basically just store the camera coordinates somehow, change them based on the desired inputs, and then inside love.draw:
Code: Select all
love.graphics.push()
love.graphics.translate ( cameraX, cameraY )
-- ...Draw stuff
love.graphics.pop()
Re: Help developing a camera that moves with mouse
Well I wanted the camera to move around when mouse 1 is down. A bit like dragging a window around. Where you're mouse doesn't represent the direction of where the camera will go, but instead where it is dragged to.
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Help developing a camera that moves with mouse
Code: Select all
local w, h
local tx, ty = 0, 0
local circles = {}
love.load = function ()
w, h = love.graphics.getDimensions()
tx, ty = -w/2, -h/2
for i=1, 100 do
table.insert(circles, {
x = love.math.random(0, w * 2),
y = love.math.random(0, h * 2),
r = love.math.random(0, 100)
})
end
end
love.mousemoved = function (x, y, dx, dy)
if love.mouse.isDown(1) then
tx = math.min(0, math.max(tx + dx, -w))
ty = math.min(0, math.max(ty + dy, -h))
end
end
love.draw = function ()
love.graphics.translate(tx, ty)
love.graphics.setColor(0, 255, 0, 100)
for _, circle in ipairs(circles) do
love.graphics.circle("fill", circle.x, circle.y, circle.r)
love.graphics.circle("line", circle.x, circle.y, circle.r)
end
end
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: Help developing a camera that moves with mouse
All I see is a blank screen
- Positive07
- Party member
- Posts: 1014
- Joined: Sun Aug 12, 2012 4:34 pm
- Location: Argentina
Re: Help developing a camera that moves with mouse
Then you are doing something wrong
for i, person in ipairs(everybody) do
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
[tab]if not person.obey then person:setObey(true) end
end
love.system.openURL(github.com/pablomayobre)
Re: Help developing a camera that moves with mouse
I got it now, I wasn't running the code independently from my other.
Or, as its own program.
Or, as its own program.
Who is online
Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 3 guests