Slick Forums

Discuss the Slick 2D Library
It is currently Mon May 20, 2013 4:50 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Zoom/Scale to camera?
PostPosted: Tue May 01, 2012 12:40 am 
Offline

Joined: Wed Apr 25, 2012 2:26 pm
Posts: 13
I've kind of amputated and adjusted koopa's camera class, tinkering about with it trying to add a zoom feature.

Here: http://slick.javaunlimited.net/viewtopic.php?t=1906

I tried using g.Scale(2,2); although this zoomed the map and character it the camera points stayed the same and I was thinking more dependant on the resolution (if they full screen it scales up to accommodate)


Any ideas on how I could go about this?

Thanks,
Carl


Top
 Profile  
 
PostPosted: Mon May 21, 2012 1:33 pm 
Offline

Joined: Wed Feb 15, 2012 10:17 am
Posts: 11
I've also been trying to do something like this for a while now.
I'll post back if I get any results.


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 3:38 pm 
Offline

Joined: Wed Feb 15, 2012 10:17 am
Posts: 11
I found a thread here that helped a lot.

http://www.java-gaming.org/topics/fixed ... /view.html


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 4:14 pm 
Offline

Joined: Thu Jan 26, 2012 5:40 pm
Posts: 79
This was my solution:

(Camera class)

Code:
public void centerOn(float x, float y) {
      //try to set the given position as center of the camera by default
      cameraX = (x - gc.getWidth() / (Globals.scale * 2));
      cameraY = (y - gc.getHeight() / (Globals.scale * 2))

(gamestate class)
Code:
public void render(GameContainer container, StateBasedGame game, Graphics g) throws SlickException {
      
      g.scale(Globals.scale, Globals.scale);
      camera.drawMap();
      camera.translateGraphics();
      super.render(container, game, g); //renders all my entities
      camera.untranslateGraphics();
      g.scale(1,1);

...

    @Override
    public void mouseWheelMoved(int change) {
       if (change < 0 && Globals.scale > 1f) {
          Globals.scale -= 1f;
       }
       
       if (change > 0 && Globals.scale < 5f) {
          Globals.scale += 1f;
       }
    }


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 5:09 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1467
Pop/Push can be handy for camera operations:
Code:
//normal rendering
//...

//"push" the current transform onto the stack
g.pushTransform();

      // add some scaling/translating/rotating
      // render ...

//"pop" the transform, leaving us with the transform we had previously
g.popTransform();

//normal rendering
//...


Top
 Profile  
 
PostPosted: Wed Jun 06, 2012 11:17 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Push and Pop are not working as expected in some cases. At least that's what I heard... It also uses only on push and one pop call as it saves it has pushed the matrix.
I always wonder why it not simply GL11.puhs/popMatrix and let the user handle the stack.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 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