Slick Forums

Discuss the Slick 2D Library
It is currently Fri Oct 19, 2018 1:44 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Wed Mar 06, 2013 4:29 pm 
Offline

Joined: Thu Feb 28, 2013 3:20 am
Posts: 1
Hi,

I've looked through the Documentation for this and tried to apply the theory to my game and it didn't work out. I've also looked around on the forums for a thread similar and I haven't found one (if there is one though, I apologise).

Slick2D offers a rendering method for TiledMaps that allows you to render only a certain part of the map.

Code:
map.render(x, y, sx, sy, ex, ey); // x, y, startX, startY, endX, endY


I want to use this for infinitely large maps (it doesn't matter how big the map is because you're only rendering a certain part of it).

The system I used to use was basically like a "Prelude of the Chambered" type thing where the map was an image containing colors that represented a tile at that position on the map. I would use this method again but given Slick has support for Tiled I want to make use of it.

The code for the, what I called a "Bitmapping" system, was this:
Code:
int x0 = xScroll >> 5; // 5 because my sprites are 32 bit, 5 zeros in binary 32.
int y0 = yScroll >> 5;
int x1 = (gc.getWidth() + 32) >> 5; // my sprites are 32 bit (32 x 32).
int y1 = (gc.getHeight() + 32) >> 5;
for (int y = y0; y < y1 + y0; y++) {
     for (int x = x0; x < x1 + x0; x++) {
          getTile(x, y).render();
     }
}

// and xScroll and yScroll are:
int xScroll = player.pos.x - (Game.WIDTH / 2);
int yScroll = player.pos.y - (Game.HEIGHT / 2);


I'm no longer getting each and every individual tile (not really any need now since Slick can do that for me).

I tried using the first four vars in the previous code and xScroll and yScroll haven't changed, which led to this:
Code:
map.render(-xScroll, yScroll, x0, y0, x1, y1); // negative scrolling because the map has to move in the opposite direction of the player.


The map was rendering, but it would jump a tile after passing every other tile in the map. I'm also pretty sure it was even doing the, what I'll call "chunking".

I'm pretty sure there aren't any forum questions because people have figured this out really quickly and easily, but I'm struggling for some reason. I'm sorry if this is painfully obvious.

So what am I doing wrong? What do I need to do? I hope I've given enough code and enough explanation.

Thanks.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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