Jump to content
  • Advertisement
Sign in to follow this  
thelegendofzaku

Switching in-between tile layers [I STILL NEED HELP]

This topic is 4555 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Since I want my game to include multiple levels, I was wondering how I can go about in doing that. I tried to input numbers in my setMap method, but that didn't seem to work. I heard that you can do this by creating a method that merges two tile number arrays, representing the levels, into one, but I'm unsure as to how to proceed. Can someone please get back to me about this. Thank You. Here's my tile layer class (note: there will be more levels besides the ones currently stated):
package de.enough.polish.example;

import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
public class TheLevels {
    private static final int [][] level1={
    {0,0,0,0,0,0,0,9,10,0,0,0,0,0,0,0,0,0},
    {6,6,6,6,6,6,6,7,8,5,5,5,5,5,5,5,5,5},
    {1,1,1,1,1,1,2,3,3,4,1,1,1,1,1,1,1,1}
    };
    private static final int [][] level2={
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1},
    {2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
    };
    private int TILE_WIDTH=64;
    private int TILE_HEIGHT=64;
    private int TILE_NUM_ROW = 3;
    private int TILE_NUM_COL = 18;

    private int [][] currentLevel;
    private TiledLayer theBoard;
    private int screenHeight;
    private int bgColor;

    /** Creates a new instance of TheLevels */
    public TheLevels(int screenHeight) throws Exception {
         this.screenHeight = screenHeight;
         setMap(1);
    }
    public void setMap(int level) throws Exception{
        Image tileImages = null;
        switch (level){
             case 1:  tileImages = Image.createImage("/street.png");
                       currentLevel = level1;
                       break;
             case 2:  tileImages = Image.createImage("/grass.png");
                        currentLevel = level2;
            }
            theBoard = new TiledLayer(TILE_NUM_COL,TILE_NUM_ROW, tileImages, TILE_WIDTH, TILE_HEIGHT);
            for (int rows=0; rows<TILE_NUM_ROW; rows++) {
              for (int columns=0; columns<TILE_NUM_COL; columns++) {
                theBoard.setCell(columns,rows,currentLevel[rows][columns]);
                }
            }
        }
        public TiledLayer getBackground(){
            return theBoard;
        }
        public int getBackgroundColor() {
            return bgColor;
        }
        public int getWidth(){
            return theBoard.getWidth();
        }
        public int getHeight(){
            return theBoard.getHeight();
        }

}


[Edited by - thelegendofzaku on April 3, 2006 11:35:36 AM]

Share this post


Link to post
Share on other sites
Advertisement
I figured out my problem, had to get rid of default case in my setMap method in my tile layer class. As a result, I was able to switch in between tile layers. Now I have another problem, I can't seem to invoke that method in my game canvas class, it's not working in my constructor, let alone my thread. I'm stumped! I don't have a clue as to where else I should invoke it. I have searched just about everywhere for this and found absolutely nothing.

[Edited by - thelegendofzaku on April 3, 2006 11:55:13 AM]

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!