Side scrolling help..

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Incrypt
Prole
Posts: 5
Joined: Thu Oct 04, 2012 3:22 am

Side scrolling help..

Post by Incrypt »

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.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Side scrolling help..

Post by Roland_Yonaba »

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.
That's fairly simple.
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
In the following example, I chose the window's height as a limit.
Hope this helps.
Incrypt
Prole
Posts: 5
Joined: Thu Oct 04, 2012 3:22 am

Re: Side scrolling help..

Post by Incrypt »

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 144 times
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: Side scrolling help..

Post by Roland_Yonaba »

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.
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Meow.

Post by Helvecta »

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:

Code: Select all

  if love.keyboard.isDown("right") and player.x < love.graphics.getWidth() - player.width then
    player.x = player.x + 1
  end
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)
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 137 times
"Bump." -CMFIend420
Incrypt
Prole
Posts: 5
Joined: Thu Oct 04, 2012 3:22 am

Re: Side scrolling help..

Post by Incrypt »

Ahh thank you very much.
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 5 guests