mike perry

Members
  • Content count

    6
  • Joined

  • Last visited

  1. mike perry

    Collision between sprite and bitmap not working

    I solved it - this example is very helpful http://jsfiddle.net/4yh8ee1f/46/
  2. How to detect collision between sprite and shape created by bitmap? In example I have sprite: this.player = this.add.sprite(0, 0, 'player') this.player.anchor.setTo(0.5) this.player.scale.setTo(0.1) And bitmap: this.bmd = this.game.add.bitmapData(2000, 2000) this.bmd.addToWorld() And then I draw shape using bmd object: this.bmd.rect(px, py + 15, 5, 500, 'rgba(255, 255, 255, 1)') Then I call this method: this.bmd.update() It looks more or less like in image. Yellow ball is my sprite. White curved line is my shape created from bitmapdata. And I want detect collision between yellow object and white line.
  3. mike perry

    Passing the cursor object to the Phaser.Sprite class

    I solved this. You can't call the update method because then you override it from the Phaser.Sprite class. Instead, just change the name to your own, e.g. move(cursors)
  4. How to pass the cursor object to a method that belongs to a class that inherits the Phaser.Sprite class? I have a class that inherits from Phaser.State in which I create a cursor object and pass it to the update method from another class. class Play extends Phaser.State { create() { this.physics.startSystem(Phaser.Physics.ARCADE) ... this.player = new Player({ game: this.game, x: 32, y: this.world.height - 150, asset: 'dude' }) this.game.add.existing(this.player) } update() { const cursors = this.input.keyboard.createCursorKeys() this.player.update(cursors) } } Player class - problem occurs in the if condition: class Player extends Phaser.Sprite { constructor({ game, x, y, asset }) { super(game, x, y, asset) this.game.physics.arcade.enable(this) this.body.bounce.y = 0.2 this.body.gravity.y = 300 this.body.collideWorldBounds = true this.animations.add('left', [0, 1, 2, 3], 10, true) this.animations.add('right', [5, 6, 7, 8], 10, true) } update(cursors) { this.body.velocity.x = 0 if (cursors.left.isDown) { this.body.velocity.x = -150 this.animations.play('left') } } } Error message: "TypeError t is undefined"
  5. mike perry

    Multiplayer game - the "script" element could not be loaded

    Thanks for reply. I solved this problem by indicate to the folder in which the scripts are located . In my case it was a folder called 'dev'. Adding this line solved the problem: app.use('/dev', express.static('dev')) Additional question Is there any way to run webpack only for build scripts not for running webpack server? The node server needs scripts to open the HTML file correctly. Scripts are built by running webpack in development mode. Is it good practise if I start webpack and node server with one command? Something like below (using "start"). "start": "concurrently --kill-others \"npm run dev\" \"npm run server\"", "dev": "webpack --mode=development", "deploy": "webpack --mode=production --config webpack.production.config.js", "server": "nodemon ./src/server/server.js --exec babel-node",
  6. How do you configure the server for this template ? => https://github.com/nkholski/phaser3-es6-webpack I'm trying to do it by following this tutorial => https://gamedevacademy.org/create-a-basic-multiplayer-game-in-phaser-3-with-socket-io-part-1/?a=13 I added two dependencies: nodemon and express. I created the server.js file with the server configuration. const express = require('express') const app = express() const server = require('http').Server(app) const path = require('path') app.get('/', function(req, res) { res.sendFile(path.resolve('index.html')) }) server.listen(8081, function() { console.log(`Listening on ${server.address().port}`) }) In the package.json file, I added a command to start the server: nodemon src/server/server.js The server starts correctly but the indicated html file can not read the scripts (" The load failed for the "script" element with the source vendor.js and app.js"). Project structure: