Isometric view in Android RPG

9submitted by 9

7submitted by 7

8represented by 8

6represented by 6

2d array -1 is empty area and 0 is full grass

this is the code i use to render the view

//map class
        private int[][] terrain = new int[20][20];
        }


        //constructor
        protected Drawable[] tiles = new Drawable[10];

        tiles[GameMap.GRASS]  = getResources().getDrawable(R.drawable.grass);
        tiles[GameMap.GRASS_WU]  = getResources().getDrawable(R.drawable.grass_wu);
        tiles[GameMap.GRASS_WD]  = getResources().getDrawable(R.drawable.grass_wd);
        tiles[GameMap.GRASS_EU]  = getResources().getDrawable(R.drawable.grass_eu);
        tiles[GameMap.GRASS_ED]  = getResources().getDrawable(R.drawable.grass_ed);

            protected void onDraw(Canvas canvas) {
        //move_Unit();

        for (int x=0;x<map.getWidthInTiles();x++) {
            for (int y=0;y<map.getHeightInTiles();y++) {

                if(map.getTerrain(x,y) != -1){

                tiles[map.getTerrain(x,y)].setBounds(x*16,y*16,(x*16) + 16,(y*16) + 16);


                if (map.getUnit(x,y) != 0) {
                    tiles[map.getUnit(x,y)].setBounds(x*16,y*16,(x*16) + 16,(y*16) + 16);
                } 
                tiles[map.getTerrain(x, y)].draw(canvas);
                tiles[map.getUnit(x, y)].draw(canvas);
                }
            }
        }

        }

    } 

Why does my view look like this and how to fix it? enter image description here

+3
source share
3 answers

Did you tag cocos2d-x ? You already have this stuff.

+1
source

It is surprisingly easy. Just think of it as a 2D service game, but things at the bottom of the screen need to be drawn later so that they appear in front of things above the screen. So, for example, if the van at the top of this screenshot was supposed to move a little forward, the bus right in front of it should be drawn after the van:

http://nanek.name/images/autotrafego_rain.jpg

, , , , - . , , , - . , .

, , 3D- .

0

, x y . , , 2d- XNA.

, x first y, , .

Your map array is square, try to make it odd and flip the parameters of the drawing function to see what happens.

0
source

All Articles