Java-Gaming.org Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (762)
Games in Android Showcase (229)
games submitted by our members
Games in WIP (847)
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  
  GAGE Examples  (Read 2831 times)
0 Members and 1 Guest are viewing this topic.
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Posted 2003-05-15 17:25:04 »

I' have the start of my engine which uses Gage to render maps. But if I try to use a tile size other than 64 x 64 I get ArrayOutofBounds exceptions in the Map rendering / GAGE code. Does anyone have examples of using it w/ different tile sizes for different maps.

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #1 - Posted 2003-05-15 17:59:53 »

Can  you post the exception? Also, make sure that you're intializing the TileManager with the correct size of tile. It would be rather annoying if you started seeing gaps simply because the sizes are wrong. :-)

Java Game Console Project
Last Journal Entry: 12/17/04
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #2 - Posted 2003-05-19 11:39:29 »

JBanes;

The Exception I'm getting follows. I'm trying to overlay map w/ 32 x 32 px. Sprites on top of what is basically your Map Example code. I use a seperate TileManager for the 32 x 32 map. But nothing is drawn.Everything worked fine before I added the additional Map.

java.lang.ArrayIndexOutOfBoundsException: -55
       at com.krypto.k2.graphics.level.Map.render(Map.java:289)
       at com.krypto.k2.graphics.level.Parallax.render(Parallax.java:132)
       at com.krypto.k2.graphics.GFXEngine.render(GFXEngine.java:195)
       at com.krypto.k2.graphics.GameEngine.run(GameEngine.java:151)

The Map in the Stacktrace is just the GAGE stuff repackaged. Here is some of my code.

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  
 protected static Parallax map = new Parallax();
    private static String[] tileNames = {"tile1.png", "tile2.png", "tile3.png", "tile4.png", "tile5.png", "blue.png"};
    private static int[] ids = new int[tileNames.length];
    private static int[] mapdata = {
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 0, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 2, 4, 0, 4, 1, 4, 1, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 5, 4, 4, 0, 3, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 1, 4, 0, 4, 4, 1, 2, 3, 4, 5, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 0, 5, 4, 0, 4, 0, 2, 3, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 0, 4, 4, 4, 0, 4, 2, 4, 4, 0, 0, 0, 0, 0, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 0, 4, 4, 0, 0, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 0, 4, 3, 4, 4, 0, 5, 0, 0, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 0, 0, 0, 0, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 0, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
       
    private static int[] mapdata2 = {
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 0, 1, 4, 4, 4, 4, 4, 4, 4, 4, 2, 4, 4, 4,
        4, 4, 4, 2, 4, 0, 4, 1, 4, 1, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 5, 4, 4, 0, 3, 4, 4, 4, 4, 5,
        4, 4, 4, 4, 4, 4, 4, 4, 2, 3, 4, 4, 4, 4, 4,
        4, 4, 1, 4, 0, 4, 4, 1, 2, 3, 4, 5, 4, 4, 4,
        4, 4, 0, 5, 4, 0, 4, 0, 2, 3, 4, 4, 4, 4, 4,
        4, 4, 0, 4, 4, 4, 0, 4, 2, 4, 4, 0, 0, 0, 0,
        4, 4, 4, 4, 4, 4, 4, 0, 0, 4, 4, 0, 0, 0, 0,
        4, 4, 4, 4, 0, 4, 4, 0, 0, 4, 4, 0, 0, 0, 0,
        4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 0, 0, 0, 0,
        4, 4, 4, 4, 4, 4, 0, 4, 3, 4, 4, 0, 5, 0, 0,
        4, 4, 4, 4, 4, 4, 4, 4, 3, 4, 4, 0, 0, 0, 0,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,
        4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4};
       
     private static int[] mapdata3 = {
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,0,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,0,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,0,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,0,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6,
        6,6,6,6,6,6,6,6,6,6,6,6,6,6,6
      };
           
    /** Creates a new instance of K2Driver */
    public GameEngine()
    {
        TileManager manager = new TileManager(64, 64);
        TileManager manager2 = new TileManager(32, 32);
       
        Map layer1 = new Map(manager, 20, 20, 800, 600);
        Map layer2 = new Map(manager, 15, 15, 800, 600);
        Map layer3 = new Map(manager2, 15, 15, 800, 600);      
        //Layer[] layers = {layer2,layer1};
        Image[] images = loadImages();              
       
        for(int i=0; i<images.length; i++) ids[i] = manager.addTile(images[i]);
        manager2.addTile(images[5]);
        // manager2.addTile(images[6]);
        for(int i=0; i<mapdata.length; i++)
        {
            if(mapdata[i] > 0) mapdata[i] = ids[mapdata[i]-1];
        }
           
        layer1.copyMap(mapdata);
        layer2.copyMap(mapdata2);
        layer2.copyMap(mapdata3);
       
        map.addMap(layer2);
        map.addMap(layer1);
         map.addMap(layer3);
        //map = new Map(layers);
    }

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #3 - Posted 2003-05-19 12:28:28 »

I'd need to see the modified version of Map to be sure (the line numbers are different), but I do notice one thing off the bat:

You're ignoring the reference numbers returned by "addTile" for manager2. It's most likely 1, not 6. (New manager, new id numbers.)

Try fixing that. If it doesn't work, send the changed Map class to jbanes@techie.com and I'll take a look at it.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #4 - Posted 2003-05-19 15:09:48 »

Your problem is that your map is smaller than your screen. (15x32 = 480 which makes for a 480x480 map which is less than the 800x600 viewport you defined). GAGE doesn't expect (or define) what will happen in this situation. BTW, another bug is here:

layer2.copyMap(mapdata3);

That should read:

layer3.copyMap(mapdata3);

In answer to your other question, GAGE will handle various sizes of Maps without fail. Using Parallax, the smaller ones will simply scroll slower than the larger ones. The only catch is that all your maps have to have the same size viewport. Since this is usually the size of the screen itself, this isn't a big deal.

You may want to look at cleaning up your code too. The cleaner you keep it, the easier it will be on you later.

Java Game Console Project
Last Journal Entry: 12/17/04
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #5 - Posted 2003-05-19 17:00:24 »

JBanes;
Thanks for your reply. I know the code is dirty, I'm just testing stuff at the moment.

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Offline jbanes

JGO Coder


Projects: 1


"Java Games? Incredible! Mr. Incredible, that is!"


« Reply #6 - Posted 2003-05-19 17:14:52 »

Quote
I know the code is dirty, I'm just testing stuff at the moment.


Just some friendly advice. I know from experience that test can often become production code. Smiley

Java Game Console Project
Last Journal Entry: 12/17/04
Offline krypto

Junior Devvie




while(true) { self.caffeinate (); }


« Reply #7 - Posted 2003-05-19 17:37:42 »

Your Right;
I'm cleaning it up before I go any further... now that it is working, thanks again. Grin

JRPG Users -  General Users Site
JRPG Developers -  The JRPG Project's Home
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (364 views)
2018-06-10 19:43:48

EgonOlsen (364 views)
2018-06-10 19:43:44

EgonOlsen (304 views)
2018-06-10 19:43:20

DesertCoockie (540 views)
2018-05-13 18:23:11

nelsongames (869 views)
2018-04-24 18:15:36

nelsongames (852 views)
2018-04-24 18:14:32

ivj94 (1303 views)
2018-03-24 14:47:39

ivj94 (424 views)
2018-03-24 14:46:31

ivj94 (1087 views)
2018-03-24 14:43:53

Solater (443 views)
2018-03-17 05:04:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!