Java-Gaming.org    
Featured games (91)
games approved by the League of Dukes
Games in Showcase (580)
games submitted by our members
Games in WIP (500)
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 / Game Mechanics / Re: Rotating a 1D matrix on: 2013-07-28 17:28:44
So I guess there are a lack of linear algebra folk around here haha Close the thread, I've figured it out after reading a bit about matrix transformations.
2  Game Development / Game Mechanics / Re: Rotating a 1D matrix on: 2013-07-22 18:49:30
When the object is rotating, the pixels themselves aren't rotating around their center, they're just rotating around another fixed point. So with that effect, there are pixel sized gaps evenly spread throughout the object. I think this happens in order to preserve the actual shape of the object.
3  Game Development / Game Mechanics / Rotating a 1D matrix on: 2013-07-22 17:02:35
So the way I render images onto the screen involves having an array of color data from a buffered image. I can manipulate that one image, through the color data, and basically render any other image into that main buffered image. The problem I'm having right now is I'm having trouble implementing a rotation transformation correctly on this array.
I've gotten strange results, where the sprite is rotating around the origin (top left corner). I couldn't really figure out how to make it rotate around it's center or any point. Also with that rotation, there are tiny gaps in the sprite while it's rotating.
4  Game Development / Shared Code / Polled Input Implementation on: 2013-07-20 05:39:40
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  
public class Input implements KeyListener, MouseMotionListener, MouseListener {
   private HashMap<Integer, Inputs> inputs = new HashMap<Integer, Inputs>();
   public int mouseX, mouseY;

   public void update() {
      for (Map.Entry<Integer, Inputs> entry : inputs.entrySet()){
         entry.getValue().update();
      }
   }

   public boolean isDown(int keyCode) {
      Inputs input = inputs.get(keyCode);
      if(input != null){
         return input.isDown;
      }
      else return false;
   }

   public boolean isClicked(int keyCode) {
      Inputs input = inputs.get(keyCode);
      if(input != null){
         return input.isClicked;
      }
      else return false;
   }

   public void keyPressed(KeyEvent ke) {
      int keyCode = ke.getKeyCode();
      if(!inputs.containsKey(keyCode)){
         Inputs input = new Inputs();
         input.toggle(true);
         inputs.put(keyCode, input);
      }
      else inputs.get(keyCode).toggle(true);
   }

   public void keyReleased(KeyEvent ke) {
      inputs.get(ke.getKeyCode()).toggle(false);
   }

   public void mousePressed(MouseEvent mo) {
      int mouseCode = mo.getButton();
      if(!inputs.containsKey(mouseCode)){
         Inputs input = new Inputs();
         input.toggle(true);
         inputs.put(mouseCode, input);
      }
      else inputs.get(mouseCode).toggle(true);
   }

   public void mouseReleased(MouseEvent mo) {
      inputs.get(mo.getButton()).toggle(false);
   }

   public void mouseMoved(MouseEvent arg0) {
      mouseX = arg0.getX() / Engine.SCALE;
      mouseY = arg0.getY() / Engine.SCALE;
   }

   public void keyTyped(KeyEvent ke) {
   }

   public void mouseClicked(MouseEvent arg0) {

   }

   public void mouseEntered(MouseEvent arg0) {

   }

   public void mouseExited(MouseEvent arg0) {

   }

   public void mouseDragged(MouseEvent arg0) {

   }

   public class Inputs {
      private int presses, absorbs;
      public boolean isDown, isClicked;

      public void toggle(boolean pressed) {
         if(pressed != isDown) isDown = pressed;
         if(pressed) presses++;
      }

      public void update() {
         if(absorbs < presses){
            absorbs++;
            isClicked = true;
         }
         else isClicked = false;
      }
   }
}


So I've experimented in different implementations of getting input from the user. This current implementation allows me to poll for constant input and also achieve a psuedo event system with the isClicked method. Also, with the addition of a hash map, I can check for any java KeyEvent or MouseEvent very quickly. Is there anything else that can be improved? I've been through many implementations, adding on what I learn over time, and I'll be glad to take any advice.
5  Game Development / Game Mechanics / Re: Java2D rendering with BufferedImage RGB data on: 2013-06-18 06:08:15
It may be a different way of rendering, but I don't think there would be any benefit, and in fact may be detrimental. It's a lot quicker to assign a color value to an array element (if pixel level manipulation is required) than to assign multiple values to a rectangle object. There are other reasons to avoid this approach, but in the end, you want to work with the API, not against, or around it.

As BurntPizza said, if performance is your top concern, consider a different API than Java2D. Personally, I haven't hit the wall with Java2D yet. I get around 1200+ FPS on a fairly modern machine at 1024x768 resolution with every pixel being touched during my rendering loop. Even my craptastic 7 year old laptop with integrated Intel video still manages to crank out 120 FPS in the same scenario. The only sure way to know is to try out a few different approaches, and see what works best for you. Smiley

Do you mind sharing your approach, it would be greatly appreciated. I've hit a huge wall and I'm sure there's something else I could do without having to move onto other API's. I would love to get that kind of performance at that resolution, but as soon as I start rendering a couple hundred images, the FPS starts sinking dramatically.
6  Game Development / Game Mechanics / Java2D rendering with BufferedImage RGB data on: 2013-06-18 05:15:38
I was wondering if I could obtain a buffered image and create another "psuedo" image from that by using the first image's color data to construct an image made up of 1 x 1 rectangles, representing the pixels of the buffered image. I'm not too sure if it would be faster than to use just regular buffered images. I figured it would be a different way of rendering and maybe get some performance gains.
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.

xsi3rr4x (47 views)
2014-04-15 18:08:23

BurntPizza (43 views)
2014-04-15 03:46:01

UprightPath (59 views)
2014-04-14 17:39:50

UprightPath (41 views)
2014-04-14 17:35:47

Porlus (57 views)
2014-04-14 15:48:38

tom_mai78101 (80 views)
2014-04-10 04:04:31

BurntPizza (139 views)
2014-04-08 23:06:04

tom_mai78101 (239 views)
2014-04-05 13:34:39

trollwarrior1 (199 views)
2014-04-04 12:06:45

CJLetsGame (207 views)
2014-04-01 02:16:10
List of Learning Resources
by SHC
2014-04-18 03:17:39

List of Learning Resources
by Longarmx
2014-04-08 03:14:44

Good Examples
by matheus23
2014-04-05 13:51:37

Good Examples
by Grunnt
2014-04-03 15:48:46

Good Examples
by Grunnt
2014-04-03 15:48:37

Good Examples
by matheus23
2014-04-01 18:40:51

Good Examples
by matheus23
2014-04-01 18:40:34

Anonymous/Local/Inner class gotchas
by Roquen
2014-03-11 15:22:30
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!