Page 1 of 1

Side scrolling help..

Posted: Sun Oct 07, 2012 11:02 pm
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.

Re: Side scrolling help..

Posted: Mon Oct 08, 2012 12:16 am
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.

Re: Side scrolling help..

Posted: Mon Oct 08, 2012 3:29 am
by Incrypt
Unfortunately that didn't work but I'll give you the files.

Re: Side scrolling help..

Posted: Mon Oct 08, 2012 8:47 am
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.

Meow.

Posted: Mon Oct 08, 2012 9:35 pm
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)

Re: Side scrolling help..

Posted: Wed Oct 10, 2012 2:55 am
by Incrypt
Ahh thank you very much.