rickydamta Posted December 6, 2015 Share Posted December 6, 2015 Hello,I have a sprite player = game.add.sprite(50, 550, 'player');When i try to load some animationsplayer.animations.add('left', [4, 5, 6, 7], 10, true);player.animations.add('right', [8, 9, 10, 11], 10, true);player.animations.add('up', [12, 13, 14, 15], 10, true);player.animations.add('down', [0, 1, 2, 3], 10, true);I get this errorTypeError: Cannot read property 'index' of undefinedThis is my full codevar menu = function(game){ console.log("%cStarting my awesome game", "color:white; background:red");}menu.prototype = { preload: function() { game.load.tilemap('level_json', '/maps/level1.json', null, Phaser.T ilemap.TILED_JSON); game.load.image('tiles', '/res/tiles_level2.png'); game.load.spritesheet('player','/res/player.png', 32, 48); }, create: function() { game.physics.startSystem(Phaser.Physics.ARCADE); // Load the map. map = game.add.tilemap('level_json'); map.addTilesetImage('tiles_level1', 'tiles'); layer = map.createLayer('Tile Layer 1'); layer.resizeWorld(); layer.wrap = true; player = game.add.sprite(50, 550, 'player'); player.animations.add('left', [4, 5, 6, 7], 10, true); player.animations.add('right', [8, 9, 10, 11], 10, true); player.animations.add('up', [12, 13, 14, 15], 10, true); player.animations.add('down', [0, 1, 2, 3], 10, true); game.camera.follow(player); game.physics.enable(player, Phaser.Physics.ARCADE); player.body.collideWorldBounds = true; cursors = game.input.keyboard.createCursorKeys(); }, update: function() { if(cursors.left.isDown) { player.body.velocity.x = -150; player.animations.play('left'); } else if(cursors.right.isDown) { player.body.velocity.x = 150; player.animations.play('right'); } else if(cursors.up.isDown) { player.body.velocity.y = -150; player.animations.play('up'); } else if(cursors.down.isDown) { player.body.velocity.y = 150; player.animations.play('down'); } else { player.body.velocity.x = 0; player.body.velocity.y = 0; player.frame = 0; } }} Link to comment Share on other sites More sharing options...
Recommended Posts