Pave

Members
  • Content Count

    16
  • Joined

  • Last visited

  1. Pave

    Phaser Destroy GameObjects

    Yeah best solution I have found is using in the preUpdate: if(this.active == false){return;} Might not be the best but it works, could be a bit tideous as I have to copy it in ever sub-class.
  2. Pave

    Phaser Destroy GameObjects

    Am I doing something wrong?
  3. Pave

    Phaser Destroy GameObjects

    The Class: class Enemy extends Phaser.Physics.Arcade.Sprite { constructor (scene, x,y) { super(scene, x,y); } preUpdate (time, delta) { super.preUpdate(time, delta); } destroyEnemy(){ this.destroy(); } } class Enemy1 extends Enemy { constructor (scene, x, y) { super(scene, x, y); } preUpdate (time, delta) { super.preUpdate(time, delta); if(this.y > 300){ this.setVelocityY(this.body.velocity.y*-1); } } } In the scene: var config = { type: Phaser.AUTO, width: gameWidth, height: gameHeight, parent: 'game', resolution: window.devicePixelRatio || 1, physics: { default: 'arcade', arcade: { debug: true } }, scene: { preload: preload, create: create, update: update } }; var game = new Phaser.Game(config); function create () { // Add Groups Bullet.bullets = this.physics.add.group(); Enemy.enemies = this.physics.add.group(); // Check if bullet overlaps with enemy this.physics.add.overlap(Enemy.enemies, Bullet.bullets, enemyHit, null, this); } function enemyHit (enemy, bullet) { // Remove the enemy enemy.destroyEnemy(); // Remove the Bullet bullet.destroyBullet(); } After the collision the Enemy gets destroyed. But the game crashes when it tries to set the velocity of the non existing enemy.
  4. Pave

    Phaser Destroy GameObjects

    After certain game actions I want to remove some Sprites. Currently I am using: this.destroy(); But this doesn''t stop the execution of the currently running "preUpdate" function. So my game crashes, because the object doesn't exist anymore but the code continues to run till the end of the preUpdate and then stops. Is there a solution for this? I don't want to use "disableBody" or something like that, because I want the Garbage Collector to pick up the sprite.
  5. Pave

    Phaser + NPM + ES6 = this-keyword problems

    At default this references a Phaser.Scene https://photonstorm.github.io/phaser3-docs/Phaser.Scene.html
  6. Pave

    Scalable Game

    @samme wow your plugin is great!👍 1. Question: Unfortunately after setting a min width/height my player can move out of the visible game area. (I want to stop the game from scaling too far down) 2. Question: If I want my game to support 4k resolutions am I fine with scaling everything upwards or should i use: { width: 4096, height: 2160, }
  7. Pave

    Scalable Game

    For better visualisation:
  8. Pave

    Scalable Game

    Hello guys, i'm back with a rather huge question. My game is currently optimized for running in full hd(1920,1080). Now I want it to scale to the users display resolution. In this article I've read that i should use "window.innerWidth * window.devicePixelRatio" to determine the users display size. Now the problem is on how to scale all my sprites to keep the same "size ratio". Because if i increase or decrease the game width/height all object have to scale with it of course. In the mentioned tutorial the guy only scaled it to match the PixelRatio and not to preserve the same sprite-gamewidth/height. Are the velocity I set for my sprites in pixels (e.g. setVelocityY(100)). So do I need to scale the velocity too?
  9. You were correct! Thanks @samme I could solve the problem by subtracting π/2 from the rotation.
  10. Pave

    Question about const's

    WebGL just increases performance of your game. Canvas rendering is the slower option. I have never seen setting this constants manually. I always set them in the "config" variable. var config = { type: Phaser.AUTO, width: 800, height: 600, scene: { preload: preload, create: create, update: update } }; var game = new Phaser.Game(config); The type "Phaser.AUTO" automatically tries to use WebGL, but if the browser doesn't support it it'll fall back to Canvas rendering. If you set the correct type in the config variable i think you can delete the two lines, but maybe a phaser expert knows more than I.
  11. Pave

    Sprite with tile texture

    I think this thread can help you (otherwise just dm the thread creator maybe he can help you):
  12. Pave

    Destroy Sprite manually

    I am very new to phaser 3 but you can add all the sprites to a group and then loop through it and destroy the ones you want.
  13. @samme thanks for the correct link. Now I found the Math function BetweenPoints(). Unfortunately I can't get it to work. Here is part of my code: class Enemy extends Phaser.Physics.Arcade.Sprite { constructor (scene, x,y) { super(scene, x,y); } preUpdate (time, delta) { this.rotateFunc(); } rotateFunc(){ let currentPoint = new Phaser.Geom.Point(this.x,this.y+this.displayHeight/2); let pointToMoveTo = new Phaser.Geom.Point(Player.players.getChildren()[0].x, Player.players.getChildren()[0].y); this.rotation = Phaser.Math.Angle.BetweenPoints(currentPoint, pointToMoveTo); this.arcadePhysics.moveTo(this, Player.players.getChildren()[0].x, Player.players.getChildren()[0].y, 30); } } In this example I want to rotate the enemy sprite to face the player sprite. For the error see the attached video. 2018-09-08 11-48-37_1.mp4
  14. Thanks @Damian Pastorini unfortunately this is just a sprite with animations, supporting only the four directions: UP, LEFT, DOWN and RIGHT. In want to be able to rotate my sprite exactly to a point, so I need to use all 360 degree and not only the four directions.
  15. Thanks for your reply. Unfortunately I can't exactly find the methods you are mentioning in the docs. https://photonstorm.github.io/phaser3-docs/Phaser.Math.html Can you maybe give me an example? Thanks in advance 👍 Pave