• Content Count

  • Joined

  • Last visited

  1. How do I create with createFromObjects and also make the objects belong to a group? I can't find a tutorial about it. Thanks for the reply.
  2. this.enemies =; this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }); this.enemies.forEach((enemy) => { if(enemy instanceof Phaser.GameObjects.Sprite) { enemy.body.setBounceX(1); } }); With this code I get enemy.body is null or if I change to enemy.setBounceX(1) I get: enemy.setBounceX is not a function The code below: this.enemies =; this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }); this.enemies.getChildren().forEach(function(enemy) { enemy.body.setBounceX(1); }, this); also doesn't work. The error message says: this.enemies.getChildren is not a function What am I doing wrong here?
  3. I could make the group move and collide with the map, but the the code only works for all of them at once. When one of the group hits the map, all group starts moving the opposite direction they were going, instead of only the object who hit the map. I'm using createFromObjects to create the Group. I created a flag to check if they're going right or left. I suppose this flag should be unique to all of them instead one for all group, but I'm learning Phaser3 and trying to make things work one step at time. Here's the code (only the part that matters): create() { this.right = true; this.enemies =; this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }); this.physics.add.collider(this.layer, this.enemies, this.bounce, null, this); } update() { this.moveEnemies(); } moveEnemies() { this.enemies.forEach((enemy) => { if(enemy instanceof Phaser.GameObjects.Sprite) { if(this.right === true) { enemy.body.setVelocityX(-20); } else { enemy.body.setVelocityX(20); } } }); } bounce() { if(this.right === true) { this.right = false; } else { this.right = true; } } Thanks in advance for any help.
  4. It's been very difficult to convert my Phaser2 games to Phaser3. For instance, I could animate objects just as simple as: this.coins =; this.coins.enableBody = true; this.mapa.createFromObjects('moedas', 'moeda', 'coins', 0, true, false, this.coins); this.coins.callAll('animations.add', 'animations', 'spin', [0, 1, 2, 3, 4, 5], 10, true); this.coins.callAll('', 'animations', 'spin'); So, this way was easy to create hundreds of objects with TiledMap, including their animations. But with Phaser3, this code doesn't work anymore. All I get is a message: this.coins.callAll is not a function Is it possible to convert the code above to Phaser 3, without changing to Tiles instead of Objects?
  5. The code: this.enemies.addMultiple( map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }) ); results in this message: this.enemies.forEach is not a function When I active debug, I see retangles around the moving enemies, but they continue not colliding with tileset.
  6. It still doesn't work. Is there any way I can use map.createFromObjects() to create sprites that already exists (hardcoded or in a class) instead of a tileset from TileMap? That way I could always create sprites with map.createFromObjects(), no matter if it's a single sprite, or thousands.
  7. Tried that solution, but unfortunely, is not working yet. Sprites don't collide with tileset, just as before.
  8. Collision works with single Sprite and the Map, but it doesn't with objects created with function createFromObjects. The callback function never displays the console.log() message. The sprites move through the tiles, never colliding with the map. I'm new to phaser3, so maybe I'm missing something. Here's the code: preload() { this.load.image('tiles', 'assets/levels_tileset.png'); this.load.tilemapTiledJSON('level1', 'assets/maps/map1.json'); this.load.spritesheet('player', 'assets/dude.png', {frameWidth: 32, frameHeight: 48}); this.load.spritesheet('enemies', 'assets/spritesheet_enemies.png', {frameWidth: 47, frameHeight: 47}); } create() { var map = this.make.tilemap({ key: 'level1' }); var tiles = map.addTilesetImage('levels_tileset', 'tiles'); this.layer = map.createDynamicLayer('blocks', tiles, 0, 0); this.layer.setCollisionByExclusion([-1]); this.player = this.physics.add.sprite(100, 450, 'player'); this.player.setBounce(0.2); this.player.setCollideWorldBounds(true); this.player.body.setGravityY(300); this.physics.add.collider(this.layer, this.player); this.right = true; this.enemies =; this.enemies = map.createFromObjects('enemies_objects', 'enemy1', { key: 'enemies' }); this.enemies.forEach((child) => { if(child instanceof Phaser.GameObjects.Sprite) { child.setFrame(4); } }); this.physics.add.collider(this.enemies, this.layer, this.bounce, null, this); } update() { this.enemies.forEach((enemy) => { if(enemy instanceof Phaser.GameObjects.Sprite) { if(this.right === true) { enemy.x += 1; } else { enemy.x -= 1; } } }); } bounce() { console.log("Collision!"); if(this.right === true) { this.right = false; } else { this.right = true; } } How can I fix this?