Hello !
I am new to Phaser and matter physics. I played around a little with Matter.js before starting with matter physics in phaser 3 as suggested in the below article
I created a simple map using Tiled and I want a circle (or ball ?) to drop into the screen and land on a collision surface. Unfortunately, I am unable to see the circle when I load my game in the browser.
By the way, how to set color to a factory object of matter physics ?
Here is my code of mainscene
, I am not sure exactly where I should add the matter physics factory object.
export default class MainScene extends Phaser.Scene {
preload() {
this.load.tilemapTiledJSON("map", "assets/tilemaps/PhysicsLevel1.json"); this.load.image( "tiles", "assets/tilesets/Overworld.png" ); this.matter.add.circle(25, 0, 50, {label:"ball", angle: 0, position: {x: 10, y: 0}, density: 10}); } create() { const map = this.make.tilemap({ key: "map" }); const tileset = map.addTilesetImage("Overworld", "tiles"); const behindLayer = map.createStaticLayer("WallLayer", tileset, 0, 0) const doorLayer = map.createStaticLayer("DoorLayer", tileset, 0, 0) doorLayer.setCollisionByProperty({ collides: true }); behindLayer.setCollisionByProperty({ collides: true }); this.matter.world.convertTilemapLayer(doorLayer); this.matter.world.convertTilemapLayer(behindLayer); this.cameras.main.setBounds(0, 0, map.widthInPixels, map.heightInPixels); //this.matter.add.circle(25, 0, 50, {label:"ball", angle: 0, position: {x: 10, y: 0}}); } update(time, delta) { }
}
Here is the index.js
import MainScene from “./main-scene.js”;
const config = {
type: Phaser.AUTO, width: 800, height: 600, backgroundColor: "#000c1f", parent: "game-container", pixelArt: true, scene: MainScene, physics: { default: "matter", matter: { // This is the default value gravity: { y: 200 }, // You can also pass in Matter.Engine config properties: // http://brm.io/matter-js/docs/classes/Engine.html#properties enableSleep: true } }
};
const game = new Phaser.Game(config);
I am a beginner, any help will be appreciated.
I am able to see the map I created in the game window but not the circle.