How Would I be able to make a side scroller using the x and y axis?
I am completely new to lua and coding and I have no frikken idea.
So far I have made my character move in all 4 directions But I cant make the collision go to the bottom or right so I decided to make it a side scroller.
If you can I'd appreciate it if you give me a code to make the character touch the bottom of the window without dissapearing.
Side scrolling help..
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Side scrolling help..
That's fairly simple.Incrypt wrote:If you can I'd appreciate it if you give me a code to make the character touch the bottom of the window without dissapearing.
Assuming the character is represented by a rectangle, if you want your character not to go down after a certain limit:
Code: Select all
function love.update(dt)
character.y = character.y+dt
local limit = love.graphics.getHeight()
if character.y+character.height> limit then
character.y = limit - character.height
end
end
Hope this helps.
Re: Side scrolling help..
Unfortunately that didn't work but I'll give you the files.
- Attachments
-
- Game.zip
- Here ya go,It's all organized,I use the player.lua for the collision and movement.Also I changed the character to "player" so that does not work with my current coding.
- (2.29 KiB) Downloaded 143 times
- Roland_Yonaba
- Inner party member
- Posts: 1563
- Joined: Tue Jun 21, 2011 6:08 pm
- Location: Ouagadougou (Burkina Faso)
- Contact:
Re: Side scrolling help..
Try to implement this by yourself.
More pointers.
Store the player's width and height in the player table (player.lua). You can use Image:getWidth, Image:getHeight for that.
Then update your collide function (still in player.lua) using the pointers I gave above. The idea is pretty simple here: you don't want the player to go off the screen height, for instance, so player.y+player.height should never go over the window's height. This implies that player.y should not not go over the window's height minus the player's height.
Same logic on x-axis, if you don't want to player to go off the right edge of the screen.
Hope this helps.
More pointers.
Store the player's width and height in the player table (player.lua). You can use Image:getWidth, Image:getHeight for that.
Then update your collide function (still in player.lua) using the pointers I gave above. The idea is pretty simple here: you don't want the player to go off the screen height, for instance, so player.y+player.height should never go over the window's height. This implies that player.y should not not go over the window's height minus the player's height.
Same logic on x-axis, if you don't want to player to go off the right edge of the screen.
Hope this helps.
Meow.
Hiya!
I slapped together a little somethin-somethin. What'cha gotta do is tell the program, "Hey, while I'm moving this direction, make sure I'm not past the screen!", like so:
This doesn't answer your question completely, but I'm not in the business of making side-scrolling engines from scratch; these tutorials might be a relevant to your interests, and even if it's not, these may help teach you the foundations of the language.
Hope this helped you, if even a little! (The attachment is just the same thing but with collision checks for when you move any particular direction)
I slapped together a little somethin-somethin. What'cha gotta do is tell the program, "Hey, while I'm moving this direction, make sure I'm not past the screen!", like so:
Code: Select all
if love.keyboard.isDown("right") and player.x < love.graphics.getWidth() - player.width then
player.x = player.x + 1
end
Hope this helped you, if even a little! (The attachment is just the same thing but with collision checks for when you move any particular direction)
- Attachments
-
- player.lua
- Just pop this in and *Bam*, collision between the player and the edges of the screen. Works for any **rectangular** object!
- (887 Bytes) Downloaded 136 times
"Bump." -CMFIend420
Re: Side scrolling help..
Ahh thank you very much.
Who is online
Users browsing this forum: Ahrefs [Bot] and 11 guests