Question about tile class

Hey guys, i’m working on a pacman clone as we speak and i’ve got a couple simple questions. I’ve set the map up as a 2d array as board[][]. Right now, i’m just looping the array and drawing the block for the tile. I’m going to make a class for drawing the objects/sprites and I realized, I don’t have any way to check collision of the tiles the way I have it as there is no rectangle…it just draws the tile. Should I make a new object for each tile so I can set a rectangle or bounding box for it?

Also, should this class be the same class I use to draw the pacman sprite? I don’t think that would cause any issues, I just don’t know if it would be a good idea to have a separate object for each and every tile. Is there an easier/better way?

Also, when I draw the tiles, they were rotated to the left it seems. I had to play with the values of the x and y and this is what I came up with which draws it correctly, but doesn’t seem correct.


	public void draw(SpriteBatch batch) {
		for (int y = 0; y < intHeight;y++) {
			for (int x = 0; x < intWidth;x++) {
			if (Board[x][y]==0) {
				batch.draw(blackTile, x*32, -y*32 + 576);
				System.out.println("Black");
			
			}
			
			if (Board[x][y]==1) {
				batch.draw(blueTile, x*32, -y*32 + 576);
				System.out.println("Blue");
			}
			
		}
		}
	}
}

I had to make the y value negative, i’m sure this is because of the reversed Y axis, but then had to add the screensize to the Y value…

hello,
i faced a similar problem with the collision detection, and because i was working with lwjgl i couldn’t use the intersect method that require 2 rectangle to check the collision, however, i build a similar method to do that, and it takes those integers variables as parameters
checkCollide(obj1_X, obj1_Y, obj1_Width, obj1_Height, obj2_X, obj2_Y, obj2_Width, obj2_Height)
and then i could do something similar to this :


for (int y = 0; y < height; y++) {
			for (int x = 0; x < width; x++) {
				                    // temporary X position of the block
                                int blockX = x * blockSize; 
                                // temporary Y position of the block 			
                                int blockY = y * blockSize;
                                //temporary type of the block 
				String block = myWorld[y][x];
												
				// bx,by,bw,bh= the player x,y,width and height
				// if it's colliding with the tile blocks
				if (checkCollide(bx, by, bw, bh, blockX, blockY, blockSize,
						blockSize)) {
					// if the tile block is from a specefic type
					if (block.equals("1")) {
                                            //do stuff
                                         }
                                   }
		             }

	              }
                      

so the whole point is to instead of using real rectangles, you just have to use their values (x,y,width and height)
i hope it helps,good luck

Thanks for the reply, but that has nothing to do with anything I asked lol. I don’t have any problem with actually doing the collision detection. I just have no way to store the values for each tile unless I make a class and make a new object for every tile from the class. I was just wondering if there was a different way. I didn’t know if it would be efficient to have 32*32 objects for just the tiles alone.

Since it appears you’re using libgdx, I’d suggest you look at libgdx’s (somewhat) new map api. Please note that any blog posts/wiki entries from 2011-2012 are probably outdated and using the old tiled-preprocessor package. Anyways - you can load tiled maps from the Tiled map editor, or .tmx format, or from the tIDE editor, and some other formats, and even if you don’t want to bother with those you can still check out the source for libgdx’s Cell class.

That’s a pretty good idea. I want to actually use Tiled anyway, as I was going to change this to use it later.

ARGH!!!

I just spent about 2 hours making the tileset and making the map, then added a new tile to the map for blockable tiles (I changed the size of the tileset but then changed it back) and now my map is all fucked up! Is there anyway to fix this? If I can just change the tile indexes back to normal it should fix it but I can’t find any way to do that…