Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (487)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (553)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Newbie & Debugging Questions / Re: Zoom in at mouse (SLICK2D) on: 2013-05-05 00:46:42
The results are always weird and unpredictable.  I don't know how to code this :X
2  Game Development / Newbie & Debugging Questions / Re: Zoom in at mouse (SLICK2D) on: 2013-05-05 00:41:42
Wait, translate BEFORE the scale?
3  Game Development / Newbie & Debugging Questions / Re: Zoom in at mouse (SLICK2D) on: 2013-05-05 00:32:04
I understood that you could do it that way, but I'm having trouble getting the transformations just right.  Could you give me any pointers?
4  Game Development / Newbie & Debugging Questions / Re: Zoom in at mouse on: 2013-05-04 23:43:36
I guess my keywords weren't sufficient.  I'll check that out. Thanks!
I don't know what LibGDX is, but I would really like to do this without ANOTHER library. I already have Slick2D and LWJGL. Another seems like it shouldn't be necessary...
5  Game Development / Newbie & Debugging Questions / Zoom in at mouse (SLICK2D) on: 2013-05-04 20:58:47
I've been working on a RTS game and I wanted to be able to zoom in with the mouse wheel toward the mouse.
In a lot of RTS games, you can hover over a unit, scroll upwards, and end up with the unit in the middle of your screen very zoomed.
That's what I'm trying to accomplish.

Here's my World.java:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
113  
114  
115  
116  
117  
package net.space.render;

import java.util.ArrayList;

import net.space.entity.Entity;
import net.space.main.ReducedSpace;

import org.lwjgl.input.Mouse;
import org.newdawn.slick.Graphics;

public class World {

   public float zX=0, zY=0;

   private float zoomLevel;
   private static final float zoomStep=0.0625f;
   
   private ArrayList<Entity> entities = new ArrayList<Entity>();
   
   
   
   public void draw(Graphics g) {
      g.scale(getZoomLevel(), getZoomLevel());
      g.translate(zX, zY);
     
      for(Entity e:entities) {
         if(e!=null) {
            e.draw(g);
         }
      }
   }
   
   
   
   public float getZoomLevel() {
      return zoomLevel;
   }
   
   public void setZoomLevel(float z) {
      zoomLevel = z;
   }
   
   
   
   public void mouseWheelZoom() {
     
        int mouseWheel = Mouse.getDWheel();
       
        if(mouseWheel==0) {
           
           return;
        }
       
        boolean positive = mouseWheel>0;
       
       
        if (positive) {
           
           addZoomLevel(zoomStep);
        }
       
        else {

           addZoomLevel(-zoomStep);
        }
       
        if(mouseWheel != 0) {
           
           zX+=(Mouse.getX()*(mouseWheel/240f))/zoomLevel;
           zY-=((ReducedSpace.h-Mouse.getY())*(mouseWheel/240f))/zoomLevel;
        }
       
        System.out.println("RAWX: "+Mouse.getX()+"\nRAWY: "+Mouse.getY()+"\nEXP: "+mouseWheel+"|"+(mouseWheel/240f)+"\nWHEEL: "+mouseWheel);
        System.out.println("X: "+zX+"\nY: "+zY);
   }
   
   public void addZoomLevel(float a) {
     
      zoomLevel+=a;
     
      if(zoomLevel>1.2375f) {
         zoomLevel=1.2375f;
      }
     
      if(zoomLevel<.1f) {
         
         zoomLevel=.1f;
      }
   }
   
   public int addEntity(Entity e) {
      entities.add(e);
      return entities.size();
   }
   public void removeEntity(int index) {
      entities.set(index, null);
   }
   public void removeEntity(String name) {
      for(int i=0;i<entities.size();i++) {
         if(entities.get(i).name.matches(name)) {
            removeEntity(i);
            return;
         }
      }
   }
   public Entity getEntity(int index) {
      return entities.get(index);
   }
   public Entity getEntity(String name) {
      for(int i=0;i<entities.size();i++) {
         if(entities.get(i).name.matches(name)) {
            return getEntity(i);
         }
      }
      return null;
   }
}


Thanks for any help!
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (15 views)
2014-08-28 18:26:30

CopyableCougar4 (25 views)
2014-08-22 19:31:30

atombrot (38 views)
2014-08-19 09:29:53

Tekkerue (33 views)
2014-08-16 06:45:27

Tekkerue (32 views)
2014-08-16 06:22:17

Tekkerue (20 views)
2014-08-16 06:20:21

Tekkerue (29 views)
2014-08-16 06:12:11

Rayexar (66 views)
2014-08-11 02:49:23

BurntPizza (42 views)
2014-08-09 21:09:32

BurntPizza (34 views)
2014-08-08 02:01:56
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!