Jump to content

Slider Puzzle Game Tile creation method


mkit
 Share

Recommended Posts

I am making a slider puzzle game - the type of game where there is a grid and an image is broken up into X tiles and the position of the tiles is shuffled and the user is required to rearrange the pieces back to the correct positions.

 

Anyway I would like to use a single image rather than break the image up into separate tile images.

 

Would appreciate advice on how you would recommend doing this.

 

The solution I have come up with so far is as follows:
 

In my preloader state

this.load.spritesheet('gameImages','assets/image1.jpg', 400, 400);

Then in my game state

 

var numTileSize = 100;	var numRows = 4;var numColumns = 4;	this.arrTileObjects = new Array();		for (var i = 0; i < numRows; i++) {		for (var j = 0; j < numColumns; j++) {				var tileObject = this.add.tileSprite(j * numTileSize, i * numTileSize, numTileSize, numTileSize, 'gameImages', 1);		tileObject.tilePosition.x = -(j * numTileSize);		tileObject.tilePosition.y = -(i * numTileSize);					this.arrTileObjects.push(tileObject);	}	}

Appreciate any feedback on this implementation and if there is an alternative implementation that would be better?

 

Thanks in advance

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...