Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (408)
games submitted by our members
Games in WIP (294)
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: Is this an efficient way to handle this? on: 2012-01-28 11:30:57
No, it is possibly the worst way you could conceivably imagine doing it. Do not use a Thread.

Cas Smiley
Ok, but what am I supposed to do as an alternative then?
If I just run it, without using the thread, my game gets too laggy..
2  Game Development / Game Mechanics / Is this an efficient way to handle this? on: 2012-01-28 11:14:44
Hi,
In my MouseInputHandler I'm checking each mouse movement which tile is getting hovered.
Now I was wondering.. Is this a good way to handle this? (I'm talking about the threading)

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  
@Override
    public void mouseMoved(MouseEvent e) {
        mousePosition = e.getPoint();
        Thread t = new Thread() {
            @Override
            public void run() {
                switch (Core.getGameState()) {
                    case INGAME: // Only perform when we're ingame so we know for sure that there are tiles..
                       if (activeTile != null) {
                            /**
                             * Get active tile, and unset if mouse is out of it
                             */

                            if (!activeTile.getEdges().contains(mousePosition)) {
                                activeTile.setBorderColor(activeTile.getDarkPixelBorderColor());
                                activeTile = null;
                            }
                        } else {
                            /**
                             * Loop trough tiles Cecks if mouse is hovered If
                             * hovered, border goes green. If not, border goes
                             * black.
                             */

                            for (int x = 0; x < Core.getTiles().length; x++) {
                                for (int y = 0; y < Core.getTiles()[x].length; y++) {
                                    Tile t = Core.getTiles()[x][y];
                                    if (t.getEdges().contains(mousePosition)) {
                                        t.setBorderColor(t.getLightPixelBorderColor());
                                    } else {
                                        t.setBorderColor(t.getDarkPixelBorderColor());
                                    }
                                }
                            }
                        }
                        break;
                }
            }
        };
        t.start();
    }

Thanks in advance!
Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (156 views)
2013-05-17 21:29:12

alaslipknot (162 views)
2013-05-16 21:24:48

gouessej (193 views)
2013-05-16 00:53:38

gouessej (187 views)
2013-05-16 00:17:58

theagentd (198 views)
2013-05-15 15:01:13

theagentd (180 views)
2013-05-15 15:00:54

StreetDoggy (225 views)
2013-05-14 15:56:26

kutucuk (250 views)
2013-05-12 17:10:36

kutucuk (245 views)
2013-05-12 15:36:09

UnluckyDevil (255 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.137 seconds with 21 queries.