How to add a Game Camera that follows the player | Love2D Basics

  Рет қаралды 35,021

Challacade

Challacade

Күн бұрын

Пікірлер: 94
@WNxExectechWarriorNation
@WNxExectechWarriorNation 3 жыл бұрын
Awesome tutorial! My son and I are following your tutorials to create a game. Thank you Kyle, keep them coming!
@Challacade
@Challacade 3 жыл бұрын
That's awesome!!
@MrInfarct
@MrInfarct 2 жыл бұрын
It must be amazing that your father helps you making video games
@giuyo
@giuyo Жыл бұрын
W Father
@nito8066
@nito8066 4 ай бұрын
how is it going
@willcubemakes
@willcubemakes 4 ай бұрын
How's your game going? :)
@lamialua26
@lamialua26 2 ай бұрын
In case anyone is interested, you can adjust how zoomed in/out the camera is by changing "cam.scale" in love.load() (e.g. cam.scale = cam.scale * 2) Then, in order for the borders to take that into account, you can also divide all the values by "cam.scale" (e.g. if cam.x < w/2/cam.scale then cam.x = w/2/cam.scale end) Not sure if it's the best way to do it but it seems to be working, hope this helps~
@HopelessGamer-rw5dz
@HopelessGamer-rw5dz 3 күн бұрын
bro cam:zoom() exists
@ismyname_jep1394
@ismyname_jep1394 2 жыл бұрын
Very well explained. I feel like even if I use these in other languages I'd still be able to implement this feature because you taught the structure of the code logic so well.
@casfewXD
@casfewXD 3 жыл бұрын
For anyone that is having problems with the right and bottom corners. In the video, he uses an upscaled tileset for the map, but if u're using a normal one and upscaling it through the code, u'll have to multiply "mapW" and "mapH" by the same scale of the map that u multiplied it in the code. Hope that this will help someone :)
@ithalogomes6651
@ithalogomes6651 2 жыл бұрын
AKDJAJDJWJFIWJD I LOVE YOU THANK YOU VERY MUCH
@mielland1621
@mielland1621 Жыл бұрын
I don't understand, can you please give me an example?
@juror12
@juror12 Жыл бұрын
Lol, thank you!
@ZigmaVR123
@ZigmaVR123 6 ай бұрын
THANK YOU SO MUCH! After having to figure out how to resize individual layers (pain) I was so worried I had run into another issue. Your comment literally saved me!
@itsaducklin
@itsaducklin 5 ай бұрын
@@ZigmaVR123 how did you manage that? I've been struggling with it as well
@justinlua4848
@justinlua4848 2 жыл бұрын
I've been trying to do a lot of this the hard way without libraries. This series is so very useful! Also if you get any errors with loading the map, try this in Tileset: Edit > Preferences > General > Export Options > Embed tilesets = true
@SandroSashz
@SandroSashz Ай бұрын
Muito obrigado! Seguindo suas instruções consegui tirar a barra preta embaixo da tela.
@Manny73211
@Manny73211 5 ай бұрын
with sti and love, i thought "ok that's a funny coincedence", but HUMP??? NAH YOU GOTTA BE TROLLING
@comfixit
@comfixit 2 жыл бұрын
Great tutorial, thanks for taking the time to make it.
@stinkyseastar3560
@stinkyseastar3560 Жыл бұрын
Thank you so much for these tutorials, I find them very helpful!
@patagain5161
@patagain5161 2 жыл бұрын
merci pour se tuto, simple pratique et très bien expliqué pas à pas
@musilicks
@musilicks 18 күн бұрын
4:53 you could also just offset in the camera lookAt call itself: Cam:lookAt(Player.pos.x + Player.size.width / 2, Player.pos.y + Player.size.height / 2)
@berserkenjoyer-vh5yj
@berserkenjoyer-vh5yj 2 жыл бұрын
hello i am newbie in Love2D and im trying to make camera fallow player as in guide, but when i write cam:attach, colon is no working i getting error how fix this?
@naelpontes8444
@naelpontes8444 2 жыл бұрын
3:28 if the layers are inside a folder, the drawing process is in any way different?
@zenolth
@zenolth 2 жыл бұрын
For the layer drawing i would just loop thru all the layers and draw them, makes it easier to add new ones ig
@andrewmartin2341
@andrewmartin2341 Жыл бұрын
I was about to post that I had problem with my code and it wasn't checking the right border. Turns out I had cam.X instead of cam.x :D Great video man, you might consider posting a link to it in your udemy course somewhere, This is the missing camera piece to the videos you have there :)
@Simon-ik1kb
@Simon-ik1kb Жыл бұрын
super useful video, thank you.
@gwrydd
@gwrydd Жыл бұрын
Just found these they’re very helpful. But please be careful you’re creating many globals which eventually is going to cause issues such as overwriting the same variable and performance issues since reading a global is slower than a local
@danielalegriasallo5551
@danielalegriasallo5551 3 жыл бұрын
Pretty useful tutorial, ty.
@tlc1432
@tlc1432 3 жыл бұрын
Thanks, this was really helpful
@sethluca
@sethluca 2 жыл бұрын
The sti thing that we imported last video doesnt work anymore for me when i try doing the layers at: 3:25. Do you know what the problem is?
@iamstill1451
@iamstill1451 2 жыл бұрын
Did that work for u ?, I am having the same problem
@blackbart2682
@blackbart2682 2 жыл бұрын
@@iamstill1451 ya it did was having same prob imported the same file with another name with lua ext
@lucaslindgren3237
@lucaslindgren3237 3 жыл бұрын
This tutorial is great!
@donnab8477
@donnab8477 Жыл бұрын
How do you keep the little guy from walking off the edge into infinity? Is that in a later video?
@jdubz6396
@jdubz6396 2 жыл бұрын
Hey! So my background is too small and originally I had it so it was scaled up 3x gameMap:draw(0, 0, 3) But when it draws individual layers it wouldn’t let me scale it. Do you know how to do this?
@ooooggll
@ooooggll 2 жыл бұрын
I have the same problem Edit: I figured it out, for anyone else who has the problem as well. First I get the camera x and y coordinates with this line: local camx, camy = cam:position() then instead of gameMap:draw(0, 0, 3, 3) I do gameMap:draw(-camx/3, -camy/3, 3, 3) Basically just draw the map at the camera's position Edit 2: turns out this has some problems with stopping the camera at the border of the screen, and likely more problems later on. Also you can ignore the whole local camx, camy line, then replace camx with cam.x and camy with cam.y.
@berserkenjoyer-vh5yj
@berserkenjoyer-vh5yj 2 жыл бұрын
@@ooooggll oh also do you know how to fix colon error in lua? when i writed exactly - cam:attach i had error by colon, but i dont understand why does it shows up please explain me if you can!
@darkfrei2
@darkfrei2 3 жыл бұрын
Can you explain how to make the same result, but without lib/camera?
@Challacade
@Challacade 3 жыл бұрын
This is how I recommend doing cameras, so I don't plan on making any other videos about it. I highly suggest sticking with the library, or looking through the camera.lua file to see how it works behind the scenes
@mrxoxtrew
@mrxoxtrew 6 ай бұрын
after doing this i realized i still have the black background and my character is on it, can you help?
@Its_ME_Nightmare
@Its_ME_Nightmare 2 жыл бұрын
I'm making a core game in love2D and need a way to make buttons that work and are on a control room area where you can press buttons on the panel this would be a huge help!
@cbaptou
@cbaptou Жыл бұрын
How do i scale individual tile layers ?
@DarkkneZPanda
@DarkkneZPanda 2 жыл бұрын
Was wondering if there was any type of zoom in function within the camera or love2d? My tiles are much smaller than 64 x 64 making my map bigger and tiles smaller. If anyone figures this out please let me know
@goladahagua273
@goladahagua273 2 жыл бұрын
very good tutorial! but I wanted to know if there is a way to make the camera similar to the celeste camera. Would you help me with this?
@idoblenderstuffs
@idoblenderstuffs 2 жыл бұрын
werent getWidth and getHeight removed from love though?
@MaverickMeier
@MaverickMeier Жыл бұрын
nooooo thats very important. why would they remove it?
@zurich_playzbg6165
@zurich_playzbg6165 Жыл бұрын
help "Error scripts/sti/init.lua:926: attempt to index local 'layer' (a nil value) Traceback [love "callbacks.lua"]:228: in function 'handler' scripts/sti/init.lua:926: in function 'drawLayer' main.lua:65: in function 'draw' [love "callbacks.lua"]:168: in function [C]: in function 'xpcall' "
@muadtheljayash7733
@muadtheljayash7733 Жыл бұрын
I'm getting the same thing, helpp
@arunolanchery8999
@arunolanchery8999 6 күн бұрын
Please help
@wegwegedgweg5892
@wegwegedgweg5892 2 жыл бұрын
I'm sorry, I was really stupid I'm really sorry, the video was great
@narikiskiran
@narikiskiran 6 ай бұрын
I am having troubles, it says that the module camera.lua is not found. Any suggesting?
@itsaducklin
@itsaducklin 5 ай бұрын
NOT camera.lua, just camera in require "camera.lua" it takes periods and uses them as like a forward slash / so, if you put camera.lua, it takes that as camera/lua, which doesn't exist. tldr; replace require "camera.lua" with require "camera"
@narikiskiran
@narikiskiran 5 ай бұрын
@@itsaducklin thank you!
@itsaducklin
@itsaducklin 5 ай бұрын
@@narikiskiran yw :>
@jubayarrahman21
@jubayarrahman21 Жыл бұрын
i can't fegure out what's going but my cod dosen't work
@eon1411
@eon1411 3 жыл бұрын
can you make a video on collisions? it would be a lot of help considering im trying to make a game that heavily relies on collision events AKA, making a video about making something happen when touching something else.
@Challacade
@Challacade 3 жыл бұрын
Next tutorial is about adding collisions where the world is solid and the player stops - I'll work on adding in collision events as well!
@microistakeneverywhere
@microistakeneverywhere 3 жыл бұрын
what about normal background? can i have the script for that?
@manikandanu2317
@manikandanu2317 2 жыл бұрын
Super... Thanks
@MaverickMeier
@MaverickMeier Жыл бұрын
these really ugly lines appear quite frequently. is there a way to get rid of them?
@ndscartridges
@ndscartridges Ай бұрын
When I add cam.lookAt(player.x, player.y) the following error occurs (please note, i have followed the tutorial to the letter, even drawing layers instead of the map.) Error PGR/lib/camera.lua:72: attempt to index local 'self' (a number value) Traceback [love "callbacks.lua"]:228: in function 'handler' PGR/lib/camera.lua:72: in function 'lookAt' main.lua:66: in function 'update' [love "callbacks.lua"]:162: in function [C]: in function 'xpcall'
@ejsuperstar
@ejsuperstar Жыл бұрын
I've been struggling for a few days now to get this right. My map is very small (20 by 20) and used small tiles (16 by 16) and just *cannot* seem to get the camera to stop at the right and bottom edges. I'm zooming in the camera using the camera zoom built into the camera. It works when I dont zoom in, but the moment I do everything goes wrong, I feel like i've tried everything I can. i know im over a year late to the party but I really need help and I dont know where else to look Edit: Less than 10 minutes after posting I figured out how to fix it. if cam.x > (mapW - w/2/camZoom) cam.x = (mapW - w/2/camZoom) end it was that easy, thats like, basically what I did for the top left, i cant believe it took me so long to figure out ... Either way uh, leaving this here incase anyone needs help too
@corentindeparscau5024
@corentindeparscau5024 6 ай бұрын
Thank you so much !
@colwarsstudiobrickfilmandm8580
@colwarsstudiobrickfilmandm8580 2 жыл бұрын
Would this work with an image instead of a tmx file?
@Challacade
@Challacade 2 жыл бұрын
If you're using an image for the background rather than a tile map, it should still work. You'd just need to use the image width/height rather than the map's width/height.
@crimson3197
@crimson3197 2 жыл бұрын
what about people who use background as a map
@piquirng
@piquirng 2 жыл бұрын
I have a problem. Player is not visible when i start the game
@anonymouslyanonymous09
@anonymouslyanonymous09 11 ай бұрын
Make sure that you are drawing the after the floor, but before anything you want to show infront of the player
@Ellohir
@Ellohir 3 жыл бұрын
Cool! Wouldn't it be easier to center the camera by changing the lookAt to player.x+player.width/2 and player.y+player.height/2 ? I feel like drawing the sprite at the center could complicate a lot the collision detection later 🤔 Anyway, great tutorial as always, bounding the camera makes it look very professional 👍🏻
@Challacade
@Challacade 3 жыл бұрын
You are right about that other option, but I actually updated the draw offset in preparation for making collisions easier. The physics library we'll be using has the center set to the middle of the collider, so now it'll line up to be the same as the draw. And personally I like having the position match the center, it's easier for me to visualize
@Ellohir
@Ellohir 3 жыл бұрын
@@Challacade awesome, thanks for your answer!
@MrInfarct
@MrInfarct 2 жыл бұрын
You're the best
@farjoos
@farjoos 2 жыл бұрын
3:36
@PerlVeemo
@PerlVeemo 2 жыл бұрын
Hump? 🤨
@thcdenton
@thcdenton 2 жыл бұрын
Love
@growingmindset7
@growingmindset7 2 жыл бұрын
this tutorial didnt worked... i am getting errors after errors and i did step by step like in the tutorial...
@MaverickMeier
@MaverickMeier Жыл бұрын
colon not dot. pay very close attention to every line
@domivincze6525
@domivincze6525 2 жыл бұрын
Hey! I have a problem that I cant figure out. the error says this: Error libraries/sti/init.lua:854: attempt to index local 'layer' (a nil value) Traceback [love "callbacks.lua"]:228: in function 'handler' libraries/sti/init.lua:854: in function 'drawLayer' main.lua:96: in function 'draw' [love "callbacks.lua"]:168: in function [C]: in function 'xpcall' I dont know what to do, please help Kyle!
@MaverickMeier
@MaverickMeier Жыл бұрын
umm I get an error when camera.lua tries to use self for lookAt
@MaverickMeier
@MaverickMeier Жыл бұрын
nvm just make sure you use the colon and not the dot
@vircobb4077
@vircobb4077 2 жыл бұрын
i kepp getting this error Error libraries/camera.lua:115: Maximum stack depth reached (more pushes than pops?) Traceback [love "callbacks.lua"]:228: in function 'handler' [C]: in function 'push' libraries/camera.lua:115: in function 'attach' main.lua:45: in function 'draw' [love "callbacks.lua"]:168: in function [C]: in function 'xpcall'
@vircobb4077
@vircobb4077 2 жыл бұрын
never mind im just stupid
@povilasbuda6490
@povilasbuda6490 8 ай бұрын
cam:lookAt(player.x, player.y) doesn't work for me, the player doesn't move when I press the movement keys Edit: I skipped the animation tutorial because I want to focus on that later
@povilasbuda6490
@povilasbuda6490 7 ай бұрын
@@TheNew54321 Thanks!
@wegwegedgweg5892
@wegwegedgweg5892 2 жыл бұрын
it gives me this error message Error libraries/camera.lua:109: attempt to index local 'self' (a nil value) Traceback [love "callbacks.lua"]:228: in function 'handler' libraries/camera.lua:109: in function 'attach' main.lua:69: in function 'draw' [love "callbacks.lua"]:168: in function [C]: in function 'xpcall' can someone help :(
@mingtongzhi
@mingtongzhi 2 жыл бұрын
Make sure you have a : instead of a . on any function that needs to have a colon. I get this error a lot when I make this mistake and it's easy to overlook
@roujiteku2114
@roujiteku2114 10 ай бұрын
just another guy with the same code error as the others. still no luck Error libraries/sti/init.lua:926: attempt to index local 'layer' (a nil value) Traceback [love "callbacks.lua"]:228: in function 'handler' libraries/sti/init.lua:926: in function 'drawLayer' main.lua:69: in function 'draw' [love "callbacks.lua"]:168: in function [C]: in function 'xpcall'
@roujiteku2114
@roujiteku2114 10 ай бұрын
okay i fixed it, i apparently renamed one of my layers in Tiled, which i did save but i apparently didn't exporting the new save. that worked, im stupid
@Walibear2
@Walibear2 5 ай бұрын
Thanks bro ur a legend
Love2D Physics (windfield) in under 10 minutes
9:59
Challacade
Рет қаралды 28 М.
Making a Game in Lua with No Experience
5:52
Goodgis
Рет қаралды 363 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Adding Collisions and Walls (from Tiled) to your Love2D Game
13:54
Easily create levels/maps for Love2D games (with Tiled)
7:56
Challacade
Рет қаралды 77 М.
Making a Blacksmithing Game in 1 Week Using Love2D
5:11
SquidGod
Рет қаралды 25 М.
INSANELY Smooth pixel ATTACK Animation Tutorial
18:54
Penusbmic
Рет қаралды 696 М.
2024's Biggest Indie Hit Was Made With... Love!   LÖVE 2D that is.
9:50
How to (easily) add Animations to a Character | Love2D Basics
14:58
The HARDEST part of game development | Devlog
6:16
Challacade
Рет қаралды 90 М.
Animating Link's Walk | Recreating Zelda
7:10
Challacade
Рет қаралды 15 М.
How to treat Acne💉
00:31
ISSEI / いっせい
Рет қаралды 108 МЛН