Slick Forums

Discuss the Slick 2D Library
It is currently Sat May 25, 2013 3:19 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
PostPosted: Tue Feb 07, 2012 3:56 am 
Offline

Joined: Tue Feb 07, 2012 3:40 am
Posts: 2
Hi guys

I've been working on a 2D top view rpg with slick and tiled for level designing. It's all working fine, but when my hero moves over some tiles he is always in front, I mean, all the tiles are back to him. I want to draw my hero in a specific layer (not superior one) but don't know how to do that.

So I started to read slick's javadoc and found renderedLine() method, but there's no example, also googled and nothing. Could someone help me? Giving me an example or at least explaining method arguments, I'm not understanding them at all.

http://slick.cokeandcode.com/javadoc/or ... edLine(int, int, int)

Forgive my english :oops:
thanks


Top
 Profile  
 
PostPosted: Tue Feb 07, 2012 8:47 am 
Offline
Slick Zombie

Joined: Wed Apr 02, 2008 1:32 pm
Posts: 1315
Location: Italy
you must organize on tiled what are your layers.
for example:

- terrain: tiles in this layer is always behind player, (example grass)
- objects: tiles in this layer is on same layer as player (example rock), can block player movements
- above: tiles in this layer is always on top of player (example tree)

you can also add property to a certain tile in particular situation.

In you code just organize in three lists your layers and render it according to this list:

renderTerrain()
renderObjects()
renderPlayer()
renderAbove()

if you have a generic object for your in-game objects, you can set a depth property to this object and then order render list according to this.

see for example here https://github.com/Gornova/MarteEngine/ ... .java#L220 and here https://github.com/Gornova/MarteEngine/ ... .java#L155

_________________
Blog | Last game Gravity Duck tribute | In progress Gravity Duck tribute


Top
 Profile  
 
PostPosted: Tue Feb 07, 2012 1:21 pm 
Offline
User avatar

Joined: Sat Jan 14, 2012 1:05 pm
Posts: 28
Location: Leipzig, Germany
I assume you have some graphics like that:
Image

So to render a unit exactly behind (north of) a wall you'd need to render line by line instead of layer by layer.
Just create a subclass of TileMap (MyMapRenderer extends TiledMap) and override renderline().
When you call the render method of your MapRenderer set lineByLine to true. This should render the map line by line from top to bottom of the screen and call renderline() each time a line is finished.
You then need to check inside renderline() if your players y position is the same as renderlines mapY (the line which was just rendered) and if thats the case draw your player. Then the render method will continue drawing the rest of the lines and thus rendering the wall over your player.
Code:
class MyMapRenderer extends TiledMap{
//...
@override
public void renderedLine(int visualY, int mapY, int layer) {
   //this gets called everytime a line is rendered. lines are rendered from top to bottom
   if(player.getY() == mapY){
     playerImage.draw(player.getX() * tilesize, player.getY() * tilesize);
   }
}


and in your gameloop call
Code:
MyMapRenderer map = new MyMapRenderer(Player player);
// (you need a reference to your players and sprites in your maprenderer)

public void render(){
  //set linebyline rendering to true so you have a chance to squeeze your player between the lines
  map.render(0, 0, 0, 0, 20, 20, true) ;
}

_________________
team red


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

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


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group