mhcdotcom

Members
  • Content Count

    15
  • Joined

  • Last visited

About mhcdotcom

  • Rank
    Member

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Hey all, I have posted my question in Game Development Stack Exchange. I've stripped the code to make it much easier to read. Feel free to answer on SE or on here. https://gamedev.stackexchange.com/questions/165350/how-can-i-get-reference-my-dialogue-box-object-in-my-scene Your help is much appreciated Thank you
  2. mhcdotcom

    DynamicLayer collision problems

    I have a very similar setup and 2 things look different from yours to mine. This line: this.layer.setCollision(1); looks something like this in my code: this.layer.setCollisionByProperty({ collides: true }) Where 'collides' is a custom property I set in Tiled app. Might not apply to your build And here, where you wrote: this.tilemap.layer.setTileIndexCallback(1, this.hitCoin, this); I assigned the `this.tilemap.layer' to a variable and add that to the collider, something like: const itemTiles = this.map.addTilesetImage(imageKey); const itemLayer = this.map.createDynamicLayer(dynamicLayerName, itemTiles, 0, 0); itemLayer.setTileIndexCallback(tileIndex , this.collectItem, this); this.physics.add.overlap(this.sprite1, itemLayer); I'm a bit of a newbie myself, so I'm not entirely sure. At least you have something you can try out. Hope it helps at all. MHC
  3. Hey All, I hope you can help me. I've asked the same question on Stack overflow. I hope you don't mind using it as a reference and answering either here or there. https://stackoverflow.com/questions/53093928/how-can-i-call-a-function-in-a-class-from-a-collider-method-when-this-is-a-diffe You're help is really appreciated. Thank you.
  4. mhcdotcom

    Basic Projectile Understanding

    Awesome. Thanks for your help.
  5. mhcdotcom

    Basic Projectile Understanding

    Thanks @samme I appreciate your time. Your method for removing the bomb looks good. Ideally i still want the bomb sprites to leave the screen before being disabled, with your method the bomb disappears as soon as it touches the world bounds. What is the difference between bomb.disableBody(true, true) and bomb.destroy() ? Is the method I mentioned in my previous comment not ideal? I could update it to look like if (bomb < this.scene.physics.world.bounds.left+bomb.width) { bomb.destroy()// or bomb.disableBody(true, true) } to ensure it is completely offscreen. I hope you can still help. Thanks again.
  6. mhcdotcom

    Basic Projectile Understanding

    I don't know what a bullet classe is. The worldbounds event is useful for when the balls are set to collide with the world bounds(collideWorldBounds = true). I want to detect when the ball has left the game world bounds when collideWorldBounds = false. Reason being, I want entities to get destroyed once they have left the world bounds so performance doesn't suffer. I'm seeing now after some research I could do something like: if (bomb < this.scene.physics.world.bounds.left) { bomb.destroy() } Would that be an ideal method for what I want to accomplish? Thanks for your time
  7. Hey All, I'm using WebPack to build my game and I've run into a scoping issue. I'll try and explain. Below is my TestScene scene/class. import 'phaser'; import Npcs from 'modules/Npcs.js'; const npcs = new Npcs() export class TestScene extends Phaser.Scene { constructor () { super('TestScene') } preload(){...} create(){ this.physics.add.collider( this.player, this.bombs, npcs.hitBomb, null, this ) } } Below is my npcs class import 'phaser'; const gameplayStates = new GameplayStates() export default class Npcs { hitBomb (player, bomb) { this.physics.pause(); player.setTint(0xff0000); this.entityDestroy() } entityDestroy () { console.log('destroyed') } } `this.player` and `this.bombs` are in place and work as expected in every way I intended. The callback in the collider method has `this`(testScene) as the context so, `this.entityDestroy()` no longer seems to work and fires app.bundle.js:116068 Uncaught TypeError: this.entityDestroy is not a function I suspect this is because the `npcs` class is not in the npcs class' scope when the method is called from the collider function. How can I get around this with the collider method? Your help would be much appreciated. Thanks all, Your help is much appreciatd.
  8. mhcdotcom

    Basic Projectile Understanding

    Hey All, var bomb = this.bombs.create(this.enemy1.x, this.enemy1.y, 'bomb'); bomb.setGravityY(-1500); bomb.body.velocity.x = -400; bomb.outOfBoundsKill = true; The bomb appears as expected. With the above in place I don't get any console errors. I got the `bomb.outOfBoundsKill = true;` reference from multiple Phaser 2 resources but cannot find the equivalent for phaser 3. I want to confirm it is being destroyed as expected but I cannot find a method for firing a callback when an image instance leaves the world bounds. I saw this one: `bomb.events.onOutOfBounds.add(functionName, this)` but this fires errors in the console. If you could help me understand what is going on here, it would be much appreciated.
  9. mhcdotcom

    Phaser 3 - Video tutorial series Free

    Beginner chiming in. I'm following along and I appreciated the tutorials for phaser 3. Keep up the good work.
  10. Thanks @samme I think I figured it out. The issue is my misunderstanding of how Tiled is intended to be incorporated into Phaser's framework. I have 2 maps(JSON files) built out from 2 different Tiled files. Phaser seems to be intended to load 1 tilemap instance that is used across an entire game build. // Where the mapObj variable is assigned in Playground.js var mapObj = mapSetup.sceneMap(this, 'map', 'tiles', 'World') // The 'tiles' reference should remain the same as what is assigned in the initial Scene(i.e. 'cave') var mapObj = mapSetup.sceneMap(this, 'map', 'cave', 'World') I thought a new instance of the tilemap would be created when a new scene starts but that doesn't seem to be the case as the name 'cave' for the tileset in the console is used and not 'tiles' when the Playground scene starts. It does makes working with Tiled and building/editing levels more maintainable but wasn't very intuitive to a beginner like me. If there is anything I'm off the mark with, please let me know.
  11. Hey Folks, I hope you can help. I am fairly new to Phaser 3 and am currently working on a platformer where my character can run, jump and collect collectibles. My game is modularised through WebPack everything else is plain JS along with the Phaser 3 framework. I am using Tiled where I export my levels as json files and the initial level loads perfectly with all collision tiles in place and working as expected. I've hit a road block with loading/starting new levels. I'll try and explain with my code to clarify. I've reduce the code significantly to make it easier to read. main.js: Entry file // Main.js import 'phaser'; import { Cave } from 'scenes/cave'; import { Playground } from 'scenes/playground'; var config = {...}, scene: [Cave,Playground] }; var game = new Phaser.Game(config); Cave.js. For the sake of conciseness, I've placed the this.scene.start in the update function so the new scene initialisation happens immediately. MapSetup function is further down. // Cave.js import 'phaser'; import MapSetup from 'modules/map-setup.js'; import CollectibleSetup from 'modules/collectible-setup.js'; const mapSetup = new MapSetup(); const collectibleSetup = new CollectibleSetup(); export class Cave extends Phaser.Scene { constructor () {super('Cave')} preload() { this.load.tilemapTiledJSON('map', 'assets/levels/cave/cave.json');// map made with Tiled in JSON format this.load.spritesheet('cave', 'assets/levels/cave/cave.png', {frameWidth: 64, frameHeight: 64});// tiles in spritesheet } create() { // Setup up map for this scene/level var mapObj = mapSetup.sceneMap(this, 'map', 'cave', 'world') this.map = mapObj.map; this.physics.add.overlap(this.player, this.stars, collectibleSetup.collectStar, null, this); }// create update () { this.scene.start('Playground') } Playground.js // Playground.js export class Playground extends Phaser.Scene { constructor () {super('Playground')} preload() { this.load.tilemapTiledJSON('map', 'assets/levels/playground/map.json');// map made with Tiled in JSON format this.load.spritesheet('tiles', 'assets/levels/playground/tiles.png', {frameWidth: 70, frameHeight: 70});// tiles in spritesheet } create() { // Setup up map for this scene/level var mapObj = mapSetup.sceneMap(this, 'map', 'tiles', 'World') this.map = mapObj.map; this.physics.add.overlap(this.player, this.stars, collectibleSetup.collectStar, null, this); }// create } MapSetup.js. The issue occurs here when the PlayGround scene is initiated. import 'phaser'; export default class MapSetup { sceneMap (ctx, key, tileSetImage, dynamicLayer) { // Map var map = ctx.make.tilemap({key: key}); console.log('map',map) // tiles for the ground layer - tilesets.name` var groundTiles = map.addTilesetImage(tileSetImage); // create the ground layer - layers[i].name var groundLayer = map.createDynamicLayer(dynamicLayer, groundTiles, 0, 0); // the player will collide with this layer groundLayer.setCollisionByExclusion([-1]); // set the boundaries of our game world ctx.physics.world.bounds.width = groundLayer.width; ctx.physics.world.bounds.height = groundLayer.height; return {map:map, groundTiles:groundTiles, groundLayer:groundLayer} } } I'll try and explain the issue as I understand it. When Playground is initiated, the following error fires in the console and it's because the the groundTiles & groundLayer variables return null so the setCollisionByExclusion doesn't work. When I console.log the map variable that get's assigned in the sceneMap function it returns: The tileset name is still referencing the cave json object and not the playground one. I don't understand why that is. My understanding is that a scene is automatically stopped when a new scene is started and that each scene is it's own class so i'm a bit baffled as to why previous references are still in place. What am I missing? Any help would be much appreciated. Thanks, All Moe
  12. mhcdotcom

    Tutorial requests

    I'm late to this party but I cannot find a satisfying tutorial for building levels through tiled for a platformer with Phaser 3. Or at least I cannot find the best method or practice to do it. Would oyu be open to a tutorial covering that?
  13. Hey All, I hope you can help me. I'm quite new to Phaser. I've looked all over google and couldn't find an answer to my question. I have an idea for a Tetris-like game. At the moment I'm learning the basics by setting up a single block to fall on the floor before another single block falls after it. The block falls from the air onto the ground just fine. The issue is: I simply want to have a collision call back happen once. I've simplified the code to make the question easier to read: function create () { this.physics.add.collider(block, ground, hitFloor, null, this); } function hitFloor () { console.log('floor hit'); } The block hits the floor and the callBack runs infinitely which makes sense because the block doesn't move and stays on the floor. I was considering setting a flag with a variable like `floorHit`. Something like: function hitFloor() { if (!floorHit) { console.log('do something') floorHit = true } } But I want to have multiple blocks fall and this won't work because the new block that gets created needs to have the `floorHit` variable set to false before it starts falling. What am I missing? Any help would be much appreciated. Thanks MHC
  14. mhcdotcom

    Fire platform collider callback once only

    Did you end up figuring this out. I'm starting with Phaser 3 and I cannot get a satisfying answer from the DOCs or anywhere online. Hope you can help, much appreciated. MHC