Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Zoom and scroll in java game - advise please.

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Zoom and scroll in java game - advise please.

    Hello all.

    I am making a game in java. I started with code for space invaders game, and am significantly altering it.

    One of those changes involves me making it so that the map is adding zoom and scroll functionality, and then making the world much bigger than will fit on a single screen at normal zoom.

    I had planned to achieve zoom by creating a parameter called zoomFactor, which can increase or decrease with user input (scroll wheel?). I would then put that in pretty much every command related to drawing my objects or moving them.


    such as xPosition += xVelocity*zoomFactor;

    The above should make objects appear to move faster when zoomed in.

    I would then have to have code that also moves objects when the zoom factor changes, which would be very easy, but would get a bit more complex when I add the ability to scroll as well.

    As for scrolling, I would simply have scrolling right be accomplished by moving all objects left by the amount I want to scroll.

    I figured I would ask for some advice first - can anyone think of easier ways to accomplish this?

    Many thanks for your time


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,400
    My Mood
    Hungover
    Thanks
    144
    Thanked 628 Times in 538 Posts

    Default Re: Zoom and scroll in java game - advise please.

    You need to separate your "model" from your "view". Your game object coordinates should be in terms of the model. Then you create a view that translates model coordinates and sizes into something the user sees.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. The Following User Says Thank You to KevinWorkman For This Useful Post:

    scottie (June 7th, 2013)

  4. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Zoom and scroll in java game - advise please.

    Ahh, very helpful.

    And yeah, I already have my game separated into move and draw, which I imagine are akin to the model and view that you mentioned. I didn't think to put all the zoom in the draw function.

    Many thanks

Similar Threads

  1. is it possible to zoom layout in android
    By shreyaskrane in forum Android Development
    Replies: 3
    Last Post: May 22nd, 2013, 06:50 AM
  2. image scroll java script trouble
    By kachora in forum Java Theory & Questions
    Replies: 3
    Last Post: July 29th, 2011, 10:22 AM
  3. JAVA netbeans - GUI how to get my scroll bar to work?!
    By camel in forum AWT / Java Swing
    Replies: 5
    Last Post: April 18th, 2011, 07:15 AM
  4. JUNG 2.0 Zoom-Function
    By humpty-hump in forum Member Introductions
    Replies: 1
    Last Post: January 22nd, 2011, 10:22 AM
  5. Zoom in and out
    By mickey in forum AWT / Java Swing
    Replies: 1
    Last Post: June 15th, 2010, 07:45 PM