Search the Community
Showing results for tags 'custom properties'.
-
I have this map created in Tiled, with an object layer for the doors. And this door object has a custom property "link", which should tell where the door goes. In phaser, I created an object layer for this doors and put them in to a new static group (this.physics.add.staticGroup). And if the player hits this door object, a method get called: this.physics.add.overlap( this.player, doors, this.enterDoor , null, this ). And there, in the enterDoor method, I want to read the "link" property, so I can switch the scene based on that value, which tells where to go next. But I am not able to get it there, it not seems to be possible to even add this value to the childs of the group, because already there, these values get lost. I am looking for a solution to this problem. These are the parts of the relevant code: Part 1, colliding with the door works without problems. Only thing there is, I have a missing sprite picture in game, but I do not want to use any sprite for the door. It should be a invisible area and if the player hits, it should go to the next scene. create() { this.map = this.add.tilemap( 'map1' ); var tileset = this.map.addTilesetImage( 'main', 'tiles' ); this.firstLayer = this.map.createStaticLayer( 'layer1', tileset ); this.secondLayer = this.map.createStaticLayer( 'layer2', tileset ); this.thirdLayer = this.map.createStaticLayer( 'layer3', tileset ); this.createPlayer( 400, 400 ); this.secondLayer.setCollisionBetween( 1, 2000 ); this.physics.add.collider( this.player, this.secondLayer); this.objectLayer = this.map.getObjectLayer( 'objectLayer' ); var doors; this.objectLayer.objects.forEach( ( object, index ) => { if (object.type === 'door') { object.key = object.name; object.setXY = { x: object.x + 16, y: object.y + 16 }; doors = this.physics.add.staticGroup( object ); //doors[ index ].set( 'link', object.link ); } }); this.physics.add.overlap( this.player, doors, this.enterDoor , null, this ); } Part 2, this is the enterDoor Method, called if the player hits the door. There I want to read the door.link property and based on that, go to the next scene. enterDoor( player, door ) { console.log( door.link ); //undefined door.disableBody( true, true) ; this.scene.switch( 'Outside', Outside ); // it should be like this: // this.scene.switch( door.link, door.link ); }
- 3 replies
-
- physics
- custom properties
-
(and 3 more)
Tagged with:
-
custom properties Tiled object custom properties get phaser 3 code
zsoltkiraly posted a topic in Phaser 3
Hi everyone! I have a problem. If I write a custom properties for the objects in the Tiled programs. How get custom properties? -
Hi everyone, I just wanted to share a new Phaser Plugin called phaser-tilemap-plus, that extends the tilemap loader and factory to support tile animations defined in the Tiled editor. It also allows you to implement collision detection against the map using polygons and rectangles within an object layer, enabling the use of sloped and curved surfaces. It will eventually also support custom properties and region-based events via the object layer. You can access and build the library from GitHub or install it directly as a Node package via NPM. Please note that it is still a work in progress, with features that are yet to be added and kinks to iron out. Anyhow, let me know what you think!
- 5 replies
-
- collision detection
- events
- (and 6 more)