Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 12:27 pm

All times are UTC




Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Mon Nov 30, 2009 7:56 pm 
Offline

Joined: Sun Nov 29, 2009 7:55 pm
Posts: 2
I made a workaround on the hardcoded render function render(int x, int y, int sx, int sy, int width, int height).

Why?
Well I wanted to make a "smooth map", where the character stands still while the map moves. And had to come up with my own solution (to lazy to use search on something I don't know the name off).

Code:
TiledMap map = null;
Vector2f pos = null;

... what ever
public void init(...) ...
{
   pos = new Vector2f(0,0)
   map = new TiledMap(...);
}



public void render(...) ...
{
map.render(
-1*(int)pos.x % map.getTileWidth(),
-1*(int)pos.y % map.getTileHeight(),
(int)(pos.x / map.getTileWidth()),
(int)(pos.y / map.getTileHeight())
,15
,15);
}




Solution
Just gonna cover the x, since the y is the same, diffrence is width/height.

x is where the map is drawn, if we were to move this one(-1) pixel to the left, it would make a illusion the center moved to the right, this is where we multiply pos.x with negative one(*-1). Also this is to simplify the input of pos.x, increasing pos.x is going left, and vice versa. To be honest, I didn't put much thought into this, it just worked on the first try.

Now we also need it to not move into infinity to the left or right, so we use posr.x mod map.getTileWidth. Now we got a moving map that jumps back after it's moved equal pixels to getTileWidth. Now to decide what sx should be, we devide pos.x with getTileWidth(), and we get how many squares we've moved.

Kinda new to this, so if feedback would be nice.
Fin.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 01, 2009 7:51 pm 
Offline
Regular

Joined: Mon Feb 23, 2009 11:32 am
Posts: 113
hmm, I hate to break it to you, but there is a tutorial on how to do this....

btw, it is called a scrolling map


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

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