Side scroller resources.

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
rnodal
Prole
Posts: 9
Joined: Sun Oct 10, 2010 11:26 pm

Side scroller resources.

Post by rnodal »

Hello all,

Does anyone have any reference about how to go about implementing a side scrolling game where the character can move back and forth also?
Any material would be welcomed. Is the tutorial in the Wiki about Z-ordering all I need?

Thank you for your time,
-r
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Side scroller resources.

Post by Robin »

Well, that depends, on your Lua and LÖVE skills, for example.

But Z-ordering might be useful, yes.

Just start writing that sidescroller, and you'll learn along the way. If you get horribly stuck, just start over. The time you've spent previously isn't wasted, because you can learn from it what works and what doesn't.
Help us help you: attach a .love.
rnodal
Prole
Posts: 9
Joined: Sun Oct 10, 2010 11:26 pm

Re: Side scroller resources.

Post by rnodal »

Hello,
Thank you for your reply.
Just in case I did not explain myself well, here is a link to a sample game that I'm trying to implement.
http://www.ripten.com/wp-content/upload ... ashers.jpg

You see, I already have my character moving up/down and left/right. The problem that I'm facing is how to relate
the z and y position. Love as far as I am concerned does not allow you to specify a z value for the image when it is render....that's why I referenced the Z-Ordering from the wiki. I want my game to have collision detection but I also need the main character to go in front or behind objects so I figured I need a z value.

In terms of my skills...well I know C/C++/Perl/PHP and I'm new to Lua but so far I have had a blast with its easy of use.
In terms of love, I'm new to it :). However I programmed a 2D game engine once (which I gave up on it because of lack of time):
http://sourceforge.net/projects/easyge/

So I'm really feel confused about the concepts involved in a making such a game as opposed to how to do it once those concepts are clear.

Any input would be appreciated it.

Thanks,

-r
User avatar
kikito
Inner party member
Posts: 3153
Joined: Sat Oct 03, 2009 5:22 pm
Location: Madrid, Spain
Contact:

Re: Side scroller resources.

Post by kikito »

The short answer is: draw last the sprites you want to be at the "front".

But how would you do that?

You need to sort them.

Lua comes with a function that helps you sort tables given a criteria: is table.sort (scroll down a bit on this tutorial)

In order to use it:
  • Make sure you have all your 'sortable entities' (the player, enemies, furniture, etc) on a table. Let's assume it's called 'entities'. When you create a new enemy/furniture/etc (inside love.load and love.update) you add it to 'entities', and when it's destroyed, you remove it from 'entities'.
  • All the entities must have a 'z' property (an integer) that property will be used for sorting the elements when drawing. z is a random name, you can call the property anything you want.
  • Inside each call to love.draw, you sort the entities table by their z attribute.
The following is an example that assumes that your entities table is called 'entities' and the z property is called 'z' (higher z means 'closer to the player')

Code: Select all

-- used for sorting. This function returns true if entity1 should be sorted 'before' entity 2
function sortByZ(entity1, entity2)
  return entity1.z < entity2.z
end
function love.draw()
  table.sort(entities, sortByZ)
  for _,entity in ipairs(entities) do
    -- draw each entity
  end
end
When I write def I mean function.
rnodal
Prole
Posts: 9
Joined: Sun Oct 10, 2010 11:26 pm

Re: Side scroller resources.

Post by rnodal »

Hello,
Thank you for taking the time to answer. That's exactly what I did.
I guess there is no black magic to side scrollers as I thought, after all.

-r
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Side scroller resources.

Post by Jasoco »

Just don't use Physics and we're golden. I too am working on a sidescroller engine. But it's not the "3D" kind. Just the plain old 2D like Mario.
Post Reply

Who is online

Users browsing this forum: No registered users and 4 guests