Cameras in Love2D (Tutorials)
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- BlackBulletIV
- Inner party member
- Posts: 1261
- Joined: Wed Dec 29, 2010 8:19 pm
- Location: Queensland, Australia
- Contact:
Re: Cameras in Love2D (Tutorials)
Thanks for your feedback. Yes it is top left. I agree that would be a good thing, but I can't be bothered changing the tutorial now; I'll leave that up to the user.
Re: Cameras in Love2D (Tutorials)
Hi BlackBulletIV. I'm having a hard time trying to mix part 2 and 3 of your tutorial. I'm trying to have a sprite (the player), the ground it walks on, and then 5 scroll planes behind.
When I create each layer, the sprite's layer has to get a scale = 0, so it's not moved by the camera, but only by the player's input. Now, no matter what value I set the other layer's scales, if they're not != 0 they will move along with the player, but if I set them to anything != 0, they'll move faster than the player.
I'm trying to figure out a way to make "1" the scale value for layers that shouldn't be moved, but I can't figure out a way. If someone has stepped onto this problem before, I'd appreciate their advice a lot.
When I create each layer, the sprite's layer has to get a scale = 0, so it's not moved by the camera, but only by the player's input. Now, no matter what value I set the other layer's scales, if they're not != 0 they will move along with the player, but if I set them to anything != 0, they'll move faster than the player.
I'm trying to figure out a way to make "1" the scale value for layers that shouldn't be moved, but I can't figure out a way. If someone has stepped onto this problem before, I'd appreciate their advice a lot.
Re: Cameras in Love2D (Tutorials)
False alarm, I managed to get it working. The trick was to forget all the layers thing. So in the love.load function you should call to this function:
And then in love.draw:
It's funny how I usually find the answer to something right after I ask for help... Sorry for the inconveniences.
Code: Select all
function createScrollPlanes()
scrollPlanes = {}
for i = 1, 5 do
local sp = {
x = 0,
y = 0,
repeatX = true,
repeatY = false,
img = love.graphics.newImage(gImagesPath.."stages/mountain/s".. i ..".png"),
q = love.graphics.newQuad(0, 0, 2560, 720, 2560, 720),
}
table.insert(scrollPlanes, sp)
end
end
Code: Select all
function love.draw()
drawBackground()
camera:set()
drawGround() --can be a tiled map
drawPlayer()
drawForeground() --in case you want a scroll layer in front of the player
camera:unset()
end
Who is online
Users browsing this forum: Bing [Bot] and 5 guests