Currently, I am in the process of developing a game using the powerful phaser game engine. To enhance the visual appeal of my game, I decided to create a sprite sheet and successfully downloaded it. The sprite sheet consists of a 256 × 384 .png file containing the frames, accompanied by a JSON file that presumably holds essential information on how to dissect these frames. However, I find myself stuck on the task of importing this sprite sheet along with the JSON file into my preload() function. Despite attempting to use a specific code snippet for this purpose, I have encountered some roadblocks. Any guidance or assistance provided on this matter would be immensely appreciated.
var game = new Phaser.Game(1200, 750, Phaser.AUTO, '', { preload: preload, create: create, update: update });
function preload(){
game.load.image('background', 'assets2/background.png');
game.load.json('robot', 'assets2/VillainSpriteSheet_json.json');
game.load.spritesheet('robot', 'assets2/VillainSpriteSheet.png');
}
var villain;
function create(){
var villainjson = game.cache.getJSON('robot');
//enable physics
game.physics.startSystem(Phaser.Physics.ARCADE);
//create background
var background = game.add.sprite(0, 0, 'background');
//villain
villain = game.add.sprite(50, 50, 'robot');
//enable phsyics
game.physics.arcade.enable(villain);
villain.body.bounce.y = .2;
villain.body.gravity.y = 300;
villain.body.collideWorldBounds = true;
}