Slick Forums

Discuss the Slick 2D Library
It is currently Thu Apr 17, 2014 6:23 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Dec 14, 2007 12:16 am 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
Well I've successfully finished implementing smooth zoom on TileMap. Unfortunately it is all bunch of unreadable stuff at the end. You can achieve it with only translate() and scale(). I assume it would be much simpler if we could draw parts of tiles (draw by floats instead of integers).
If somebody has an idea how to do it better or improve this thing, please let me know.

It is all here, I removed variables like screen resolution and tile size, calling functions like getTileWidth() makes it unreadable as it can get... this is specific for 800x600 resolution and tile size 32x32

Code:
   public void render(GameContainer container, Graphics g) {
        g.scale(scale,scale);
       
        // determine how much tiles scaled map needs for displaying on screen
        renderWidthInTilesScaled = (int)(KrajnaGame.getGameWidth()/scale/KrajnaGame.getTileWidth())+2;
        renderHeightInTilesScaled = (int)(KrajnaGame.getGameHeight()/scale/KrajnaGame.getTileHeight())+2;

        // move the scaled map so it is centered same as original map
        g.translate(-400 + 400/scale, -300 + 300/scale);       

        // needed for culling map outside the screen when zoomed in and rendering whole map when zoomed out
        g.translate(-400 + 400/scale, -300 + 300/scale);       
        int scaledx = 32*(int)(400f/32) - 32*(int)(800f/(scale*2)/32+1);
        int scaledy = 32*(int)(300f/32) - 32*(int)(600f/(scale*2)/32+1);
        worldMap.render(
                scaledx,
                scaledy,
                (int)(mapRenderStartX) + scaledx / 32,
                (int)(mapRenderStartY) + scaledy / 32,
                renderWidthInTilesScaled,
                renderHeightInTilesScaled);
        g.resetTransform();
       
    }


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