Sign in to follow this  
NickyP101

Simple Tile Based Q

Recommended Posts

NickyP101    146
Programming Lang Java: Currently in my tiles based game, the player moves a tile at a time. I left it like this while i designed the rest, and now ive come back to it. I want the player to move 1 pixel at a time, not a tile at a time. At the moment i am drawing the tiles directly to the BufferStrategy, this is giving me a frame rate of lyk 100 FPS. Now to achieve what i explained in my first paragraph, i assume i would have to use some algorithm to figure out which tiles i need to clip before drawing them to the buffer strategy. But i just cant get it around my head tonight. Haha the simpler way is to draw the tiles of the map to a buffered image and then crop that image and draw that to the bufer strategy, but that is highly inefficient, when i used to do that with my relitively small map i was getting a FPS of 16, and that was before i implemented the networking aspect lol Any ideas? Any help would be great :) Thanks in advance, Nick

Share this post


Link to post
Share on other sites
benryves    1999
I've found that the fastest way to smooth-scroll tilemaps is to render an extra border of tiles and one screensworth to an off-screen buffer. So, if your screen can display 16x16 tiles at once, draw 18x18 tiles to the offscreen buffer. Now, as you character moves, take the offset and blit a 16x16 tile area from the offscreen buffer to the screen based on that. If the offset becomes larger than the width of a tile, you'll need to shift the entire offscreen buffer by one tile in the opposite direction then fill in one new row or column at the new exposed edge then reset the offset and change the player's position by one whole "unit" (as you're currently doing).
As far as actually implementing that goes, I'm used to doing this in ASM so I am just shifting large linear blocks of bytes around in memory so it's very very fast - even on low end hardware.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this