Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (477)
Games in Android Showcase (107)
games submitted by our members
Games in WIP (536)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Image color not recognized 2nd time.  (Read 1396 times)
0 Members and 1 Guest are viewing this topic.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Posted 2012-04-13 21:21:05 »

Hello there. I continue to code my game and, after 2 hours of debugging i still get a problem:
I am loading the game map from an .png image. When i run the game on first map it's ok, the code read the color, but when i change the map, the code doesn't recognize the same color.

Here is my code (based on Catacomb Snatch) ((the problem is at System.out.println("spawn?"), in that if)) :



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  
public void loadLevel(Level l) {
      currentLevel = l;
     
      BufferedImage bufferedImage = l.levelImage;
     
      int w = bufferedImage.getWidth();
        int h = bufferedImage.getHeight();
        Level.levelWidth = w;
      Level.levelHeight = h;
     
      Level.tiles = new Tile[h*w];
      Level.unpassableTiles = new Bag();
      Level.passableTiles = new Bag();
      Level.enemy = new Bag();
      Level.spawners = new Bag();
      Level.others = new Bag();

        int[] rgbs = new int[w * h];
        Arrays.fill(rgbs, 0xffA8A800);
        bufferedImage.getRGB(0, 0, w, h, rgbs, 0, w);
        l.player = new Player(256, 256, 0);
       
        int counter = 0;
        for (int y=0; y<h; y++) {
            for (int x=0; x<w; x++) {
                int col = rgbs[x + y * w] & 0xffffff;
                Tile tile = null;
                if(col == 0xff00ff) {
                   System.out.println("spawn?");
                   tile = new FloorTile(x*FloorTile.getWidth(), y*FloorTile.getHeight());
                   l.player.setX((float) (x*FloorTile.getWidth() + FloorTile.getWidth()/2 - l.player.getWidth()/2));
                   l.player.setY(y*FloorTile.getHeight());
                   l.player.setLastX(l.player.getX());
                   l.player.setLastY(l.player.getY());
                } else if(col == 0xffffff) {
                   tile = new FloorTile(x*FloorTile.getWidth(), y*FloorTile.getHeight());
                } else if(col == 0xff0000) {
                   tile = new WallTile(x*WallTile.getWidth(), y*WallTile.getHeight());
                } else if(col == 0x000000) {
                   tile = new HoleTile(x*HoleTile.getWidth(), y*HoleTile.getHeight());
                }  else if(col == 0x999999) {
                   tile = new FloorTile(x*FloorTile.getWidth(), y*FloorTile.getHeight());
                   Level.spawners.add(new Spawner(x*32, y*32));
                }
               
                Level.tiles[counter] = tile;
                counter++;
               if(!tile.isPassable())
                  Level.unpassableTiles.add(tile);
               else if(tile.isPassable())
                  Level.passableTiles.add(tile);
            }
        }
}




EDIT: Hmm, i did some tests and i realised that the color is recognized only in first level(map).

Getting a project done is by far the most hard thing in game development.
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #1 - Posted 2012-04-13 21:45:18 »

Ok, the problem is solved. I don't know why, but the maps weren't read by eclipse, so i reinitialized them. Sorry for this topic. This can be closed/deleted. Thanks!

Getting a project done is by far the most hard thing in game development.
Offline _Al3x

Senior Member


Medals: 7


Indie Games FTW!


« Reply #2 - Posted 2012-04-13 22:44:51 »

Whenever you change files, make sure to press F5 in Eclipse to refresh. I even had to select in the package explorer the specific folder where was my conflicting file and the press F5 for Eclipse to notice the changes.

Good luck and keep it up! Smiley

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Cruiser

Junior Member


Medals: 1
Projects: 1


Twitter: @totallymorten


« Reply #3 - Posted 2012-04-13 22:57:19 »

One advice here. Go to menu Window -> preferences and then search for "refresh" in the filter.

Then enable:

* Refresh during startup
* Automatic refresh

These help a lot!
Offline marcuiulian13

Senior Member


Medals: 5
Exp: 3 years



« Reply #4 - Posted 2012-04-13 23:29:24 »

Okay. Thanks, i am tired to refresh the files after i edit one level image and it doesn't update.  Tongue

Getting a project done is by far the most hard thing in game development.
Offline ra4king

JGO Kernel


Medals: 338
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-04-14 00:25:41 »

You can turn on automatic refresh in Eclipse. Window -> Preferences -> General -> Click on Workspace. Make sure the first 4 boxes are checked.

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Riven (18 views)
2014-07-29 18:09:19

Riven (13 views)
2014-07-29 18:08:52

Dwinin (12 views)
2014-07-29 10:59:34

E.R. Fleming (31 views)
2014-07-29 03:07:13

E.R. Fleming (12 views)
2014-07-29 03:06:25

pw (42 views)
2014-07-24 01:59:36

Riven (41 views)
2014-07-23 21:16:32

Riven (28 views)
2014-07-23 21:07:15

Riven (29 views)
2014-07-23 20:56:16

ctomni231 (60 views)
2014-07-18 06:55:21
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!