I’m currently trying to make a chess game using cocos2d js, what would be a good way to approach this. I was experimenting with cocos studio and i’m was making separate individual tiles for each space on a chess board because I think it would be easier to recognize in code. Some examples may be if sprite(pawn) movesto tile 3{
…
…
…etc, or
if sprite1 tries to move to tile 8 and tile 8 status == occupied{
…
…
…
But i know that making each individual tile new objects could affect performance although they wont be moving, there will be so many of them. So is there a good way to make a good checker/chess board scene?
Many ways, as usual to do this: do what you’re doing with 64 tiles, or a single background image with pieces on top, or use a tilemap editor for the board (probably overkill). People work/think differently, and I would probably create my UI and a positioned node for reference in cocostudio and then generate the tiles and pieces in code since it’s a repetitive task instead of having to create 64 different sprites in cocostudio?
Are you doing a top down view to start? Are you planning to animate the pieces? Are you planning to support multiple views of the board (top down, 2.5d perspective, etc)?
I want to do a top down view, where you can see your pieces and opponents pieces, with enough space on the side and bottom for like a menu bar, and pieces captured. I will have animations such as if two pieces collide or you activate a special, etc etc. It would be nice to be able to rotate the camera for a better view of my opponents pieces. 2.5d would probably be ideal considering i don’t want the game to look to flat and with the animations and being able to rotate the camera 2.5d would probably be the way to go.
I’d probably just start with the top down view then. The node hierarchy might be something like:
Board (Node: centered, either no size or size set to tile size * 8)
->BoardSpace (Sprite: child of board, either black.png or white.png, )
->BoardPiece (Sprite: child of board, one of knight.png, etc)
Positioning would be done either in CocoStudio or in code based on row and col. If you layout all spaces and pieces in cocostudio then you’ll want to name them or give them a tag so you can identify each when you load it in.
Look into the Menu class, too. I find calling Menu.alignItemsInRows() is much easier than using a CocoStudio when I just want a grid. Menu.alignItemsInRows() takes an arbitrary number of arguments, each one of which is the length of one of the rows. The z-order of the MenuItems determines what order they go in. So for an 8x8 chessboard, you would call “[your menu].alignItemsInRows(8,8,8,8,8,8,8,8);”, after making sure your tiles are ordered so as to alternate black and white.
Thanks for the replies, i will be looking into this within the next couple of days.