Search the Community
Showing results for tags 'animations.add'.
-
Would someone be kind enough to help me understand why this isn't working? I am trying to create 10 enemies, randomly placed in my game world. If I comment out the broken code inside my Update() function, it works, and displays 5 enemies in a row. However, there are two problems that I do not understand how to fix: In my Create() function, I do not understand why I am unable to use this.sprite.animations.add when creating a new sprite within the group. If I un-comment this code (line 30), it no longer creates the 5 enemies on the screen, just 1. I'm not sure why that happens, either. Considering the fact that the .create method is called and places the enemy before the animations get added, it would logically follow that the enemies would display, but without moving. In my Update() function, I do not understand why I keep getting the error: My code is below. Any help would be appreciated. Enemy = function(game) { this.game = game; this.sprite = null;};Enemy.prototype = { preload: function () { this.game.load.spritesheet('enemy', 'images/RedMage.png', 64, 64, 8); }, create: function () { var enemies; enemies = game.add.group(); for (var i = 0; i < 5; i++) { // This creates a new Phaser.Sprite instance within the group // It will be randomly placed within the world and use the 'baddie' image to display // enemies.create(360 + Math.random() * 200, 120 + Math.random() * 200, 'enemy'); enemies.create(150 + (100 * i), 50, 'enemy'); // Player animations // this.sprite.animations.add('down', [0, 1], 7, true); // this.sprite.animations.add('left', [2, 3], 7, true); // this.sprite.animations.add('right', [4, 5], 7, true); // this.sprite.animations.add('up', [6, 7], 7, true); // Default animation // this.sprite.animations.play('down'); } }, update: function() { game.world.forEach(function(enemy) { var direction = Math.floor(Math.random() * (4 - 1 + 1) + 1); if (direction == 1) { // Move north enemy.sprite.y -= SPEED; } else if (direction == 2) { // Move east enemy.sprite.x += SPEED; } else if (direction == 3) { // Move south enemy.sprite.y += SPEED; } else if (direction == 4) { // Move west enemy.sprite.x -= SPEED; } }); }}
-
Well i'm updating old Phaser code to 1.0 Well some renaming and function moved to new objects and so on I'm a bit stuck here: function preload() { myGame.world.setSize(320, 416); myGame.load.image('logo', 'assets/images/logo.png'); myGame.load.image('bg', 'assets/images/bg_prerendered.png'); myGame.load.atlasJSONArray('tiles', 'assets/textureAtlas/breakout.png', 'assets/textureAtlas/breakout.json');}function create() { myGame.add.sprite(0, 0, 'bg'); paddle = myGame.add.sprite(myGame.world.width / 2, myGame.world.height - 48, 'tiles'); paddle.animations.add('paddle_big', ['paddle_big.png'], 10, false, false); paddle.animations.add('paddle_small', ['paddle_small.png'], 10, false, false);}And the error that hit's me is : Uncaught TypeError: Cannot read property 'uuid' of null phaser.js:20495 Phaser.AnimationManager.addphaser.js:20495 creategame.js:277 Phaser.StateManager.loadCompletephaser.js:7851 Phaser.Game.loadCompletephaser.js:10273 Phaser.SignalBinding.executephaser.js:8426 Phaser.Signal.dispatchphaser.js:8312 dispatchphaser.js:8115 Phaser.Loader.nextFilephaser.js:23026 Phaser.Loader.jsonLoadCompletephaser.js:22920 _xhr.onload What i checked is that: paddle.animations.add('paddle_big'); - works, but there isn't a frame name specified paddle.animations.add('paddle_big', [1], 10, false, false); - agian works but is hard to tell what frame is 1,2,3, etc. So I suppose that there is new way of doing this but I'm stuck on this from one hour and decided to share my frustration. I checked old examples TS, and all news examples which are so little compared with TS examples so I'm offering to convert some of the old ones to 1.0 because I'll gain some more knowledge too but first I must pass the atlas texture problem.
- 7 replies
-
- atlasJSONArray
- texture
-
(and 2 more)
Tagged with: