First, welcome to LÖVE.
Second, whenever you need help it better to upload a .love file so we can look through your code.
To create boundarys is pretty simple, a picture is a square.
Squares have 4 points.
Top left point - x,y
Top right - x+width,y
Bottom left - x,y+height
Bottom right - x+width,y+height
So lets say you have a window thats 500px by 500px, meaning 500 wide 500 tall.
Now lets say our picture is 32x32
Lets set those into variables.
Code: Select all
picture = {} --setting picture to a table to hold values
picture.x = 250 -- setting player x value to middle of screen
picture.y = 250 -- setting player y value to middle of screen
picture.width = 32 -- setting width
picture.height = 32-- setting height
That should go in you love.load or your player file
Now we have the begining to a simple collision system, however checking boundarys is alot easier.
First lets see where this x is, if its less then 0 its gone to far!
Put this in your update.love
Code: Select all
if picture.x < 0 then picture.x = 0 end -- so if picture tries to go to far left it cant!
Now lets do the same for the other side and the top and bottom.
Code: Select all
if picture.x < 0 then picture.x = 0 end
if picture.y < 0 then picture.y = 0 end
if picture.x + picture.width > 500 then picture.x = 500 - picture.width end
if picture.y + picture.height > 500 then picture.y = 500 - picture.height end
Remember that goes in update.
So whats left? Drawing your picture and making it move.
Make sure when drawing you use picture.x and picture.y as the x and y of the image.
Put the picture under picture.pic like this.
Code: Select all
picture.pic = love.graphics.newImage("whatever.png")
Also put that in love.load after you set picture to a table.
Then just create your movement using love.keyboard.isDown("") and make it update the picture.x and picture.y
Hope this helped i probs should have changed name of the var picture but was im at work not much time to think of var names.