d0zzerr

Members
  • Content Count

    2
  • Joined

  • Last visited

  1. d0zzerr

    Same code different working

    /* * https://labs.phaser.io/edit.html?src=src\physics\matterjs\advanced%20shape%20creation.js */ const config = { type: Phaser.AUTO, type: Phaser.AUTO, parent: 'phaser-example', width: 600, height: 800, scene: { preload: preload, create: create }, physics: { default: "matter", matter: { // debug: true } } }; var game = new Phaser.Game(config); function preload() { // Load sprite sheet generated with TexturePacker this.load.atlas('sheet', 'assets/physics/fruit-sprites.png', 'assets/physics/fruit-sprites.json'); // Load body shapes from JSON file generated using PhysicsEditor this.load.json('shapes', 'assets/physics/fruit-shapes.json'); } function create() { var shapes = this.cache.json.get('shapes'); this.matter.world.setBounds(0, 0, game.config.width, game.config.height); this.add.image(0, 0, 'sheet', 'background').setOrigin(0, 0); // sprites are positioned at their center of mass var ground = this.matter.add.sprite(0, 0, 'sheet', 'ground', {shape: shapes.ground}); ground.setPosition(0 + ground.centerOfMass.x, 0 + ground.centerOfMass.y); // position (0,0) this.matter.add.sprite(200, 20, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(250, 20, 'sheet', 'banana', {shape: shapes.banana}); this.matter.add.sprite(360, 20, 'sheet', 'orange', {shape: shapes.orange}); this.matter.add.sprite(400, 20, 'sheet', 'cherries', {shape: shapes.cherries}); this.matter.add.sprite(200, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(250, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(300, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(350, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(400, 200, 'sheet', 'crate', {shape: shapes.crate}); this.input.on('pointerdown', function (pointer) { this.matter.add.sprite(pointer.x, pointer.y, 'sheet', 'banana', {shape: shapes.banana}); }, this); } /* * This example show how to load complex shapes created with PhysicsEditor (https://www.codeandweb.com/physicseditor) */ const config = { type: Phaser.AUTO, type: Phaser.AUTO, parent: 'phaser-example', width: 600, height: 800, scene: { preload: preload, create: create }, physics: { default: "matter", matter: { // debug: true } } }; var game = new Phaser.Game(config); function preload() { // Load sprite sheet generated with TexturePacker this.load.atlas('sheet', 'assets/physics/fruit-sprites.png', 'assets/physics/fruit-sprites.json'); // Load body shapes from JSON file generated using PhysicsEditor this.load.json('shapes', 'assets/physics/fruit-shapes.json'); } function create() { var shapes = this.cache.json.get('shapes'); this.matter.world.setBounds(0, 0, game.config.width, game.config.height); this.add.image(0, 0, 'sheet', 'background').setOrigin(0, 0); // sprites are positioned at their center of mass var ground = this.matter.add.sprite(0, 0, 'sheet', 'ground', {shape: shapes.ground}); ground.setPosition(0 + ground.centerOfMass.x, 0 + ground.centerOfMass.y); // position (0,0) // changed order add sprite this.matter.add.sprite(200, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(250, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(300, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(350, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(400, 200, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(200, 20, 'sheet', 'crate', {shape: shapes.crate}); this.matter.add.sprite(250, 20, 'sheet', 'banana', {shape: shapes.banana}); this.matter.add.sprite(360, 20, 'sheet', 'orange', {shape: shapes.orange}); this.matter.add.sprite(400, 20, 'sheet', 'cherries', {shape: shapes.cherries}); this.input.on('pointerdown', function (pointer) { this.matter.add.sprite(pointer.x, pointer.y, 'sheet', 'banana', {shape: shapes.banana}); }, this); } the codes are the same but the results are different. When I run the first code block, the objects are continuously moving, but when I run the second code it works correctly. The objects stop after a while. Could it be a bug or something else I did not notice you can try these codes on https://labs.phaser.io/edit.html?src=src\physics\matterjs\advanced shape creation.js
  2. preload(){ this.load.atlas('sheet','img/images.png','img/images.json'); this.load.json('shapes','img/shapes.json'); } create() { this.shapes = this.cache.json.get('shapes'); this.platform = this.matter.add.sprite(x,y,'sheet','platform.png',{ shape: this.shapes.platform}); // add sprite this.bottle = this.matter.add.sprite(this.width/2,this.height-24-16,'sheet','Bottle.png',{ shape: this.shapes.Bottle}); this.bottle.setBounce(0.5,0.75); // for(let i=0;i<5;i++){ // let x = 64+Math.floor(Math.random()*(this.width-64)); // let platform = this.matter.add.sprite(x,2*this.height/3 - i*156,'sheet','platform.png',{ shape: this.shapes.platform}); // } } First of all my English a little bad sorry for that. When i add platform and bottle on the screen it working properly. But when i want to create one more platform same code after the bottle create it doesnt work. If i try to add before the bottle it work good. i added media that show you wrong working : https://youtu.be/W470LsI9IWI this is the not working : https://youtu.be/1GBtUHbRPiE