jasper1990

Members
  • Content Count

    9
  • Joined

  • Last visited

  1. I am trying to get some ideas on designing enemy movement patterns in phaser 3. First, I am trying to separate everything into discrete files such as custom game objects, scene, then the actual game file. I thought about using state machines and ran across this https://github.com/jakesgordon/javascript-state-machine. I kind of want something modular yet extandable. Should, I just put the path for each NPC and Enemy in a JSON or XML file? thanks!
  2. Thanks, I was thinking about making a custom .delete() function to destroy everything for Dialoguebox. I just wanted a more elegant solution; whenever I add more game objects. thanks!!
  3. I have a dialogue box object that I custom made for an adventure/shooter game. In the code below, the custom object has a graphic component to draw a black background. when I use the "destroy" method, only the text goes away. thank you for any help var config = { type: Phaser.AUTO, width: 800, height: 600, parent: 'phaser-example', backgroundColor:'#ffffff', scene: { create: create, update: update } }; var game = new Phaser.Game(config); var dialogue; //var timerEvent; //var count = 0; //var str = "this is the test string that will be used for this demo"; class DialogueBox extends Phaser.GameObjects.Text { constructor(params){ super(params.scene, params.x + 10, params.y + 10, '', params.style); this.setDepth(1); this.graphics = params.scene.add.graphics(); this.graphics.fillStyle(0, 1); this.graphics.fillRect(params.x, params.y, 1000, 200); this.strcontent = params.text; this.timerEvent = params.scene.time.addEvent({ delay: 50, repeat: params.text.length }); this.count = 0; params.scene.add.existing(this); } update(){ this.renderText(this.timerEvent.getProgress()); } renderText(progress){ if(progress > 0.98){ this.setText(this.strcontent.substring(0,this.count)); this.count += 1; } } } function create() { // Pass in a basic style object with the constructor //dialogue = this.add.text(10, 200, ' ', { fontFamily: 'Arial', fontSize: 16, color: '#ffffff' }).setDepth(1); //timerEvent = this.time.addEvent({ delay: 50, repeat: str.length }); dialogue = new DialogueBox({scene: this, x: 0, y: 200, text:"this is the test string that will be used for this demo", style:{ fontFamily: 'Arial', fontSize: 16, color: '#ffffff' }}); this.input.keyboard.on('keydown', function (event) { dialogue.destroy(); }); } function update(){ //enderText(timerEvent.getProgress()); dialogue.update(); } /*function renderText(progress){ if(progress > 0.98){ dialogue.setText(str.substring(0,count)); ++count; } }*/
  4. I thought it would be better to cram two questions into this Topic. I wanted to know how to handle rendering many NPCs on a screen and also loading dialogue. thank you for any help!
  5. How can I get the bounds of the world without hardwriting it in? Does the scene come with a rect?
  6. I added a zip file, but specifically I get an issue with the following : function create (){ var Bullet = Phaser.Class({ Extends: Phaser.GameObjects.Image, initialize: function Bullet(scene) { Phaser.GameObjects.Image.call(this, scene, 0, 0, 'bullet'); this.speed = 0; this.born = 0; }, fire: function (argplayer) { this.setPosition(argplayer.x, argplayer.y); this.speed = 20; this.born = 0; }, update: function (time, delta) { this.y += this.speed * delta; this.born += delta; if (this.born > 1000) { this.setActive(false); this.setVisible(false); } } }); player = new Player(this, 100, 400); this.anims.create({ key: 'middle', frames: this.anims.generateFrameNumbers(PLAYER_LABEL, { start: 0, end: 2 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'left', frames: this.anims.generateFrameNumbers(PLAYER_LABEL, { start: 3, end: 5 }), frameRate: 10, repeat: -1 }); this.anims.create({ key: 'right', frames: this.anims.generateFrameNumbers(PLAYER_LABEL, { start: 6, end: 8 }), frameRate: 10, repeat: -1 }); this.bullets = this.add.group({ classType: Bullet, runChildUpdate: true }); this.lastFired = 0; cursor = this.input.keyboard.createCursorKeys(); KeyZ = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.Z); KeyX = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.X); KeyC = this.input.keyboard.addKey(Phaser.Input.Keyboard.KeyCodes.C); } function update (time, delta){ if (cursor.right.isDown) { player.moveRight(); if(player.checkBoundary(256,512, 0)) { player.moveLeft(); } } else if(cursor.left.isDown) { player.moveLeft(); if(player.checkBoundary(256,512, 0)) { player.moveRight(); } } else if(cursor.up.isDown) { player.moveUp(); if(player.checkBoundary(256,512, 0)) { player.moveDown(); } } else if (cursor.down.isDown) { player.moveDown(); if(player.checkBoundary(256,512, 0)) { player.moveUp(); } } if(KeyZ.isDown) { player.aimLeft(); } if(KeyX.isDown) { player.aimMiddle(); } if(KeyC.isDown) { player.aimRight(); } if (cursor.space.isDown && time > this.lastFired) { var bullet = this.bullets.get(); bullet.setActive(true); bullet.setVisible(true); if (bullet) { bullet.fire(player); this.lastFired = time + 100; } } player.renderAim(); }
  7. I'm developing a rail shooter and I'm trying to copy the bullet class from phaser 3 example here : https://labs.phaser.io/view.html?src=src\games\defenda\test.js&v=3.2.1. I'm having issues with no bullets appearing *when I press spacebar*, there appears to be no errors in the console either. I'm not entirely sure how groups work, but could someone explain to me? I'm using phaser 3.2.1 railshooter.zip
  8. I keep getting the error : 'add' of undefined for this.physics.add.sprite(100, 450, 'dude'); but this.add.sprite works but then I cant use setVelocityY either. my configure is this var config = { type: Phaser.AUTO, width: 800, height: 600, backgroundColor:'#00cd00', physics: { default:'impact', impact: { x: 0, y: 0, width: 800, height: 1200, thickness: 32 } }, scene: { preload: preload, create: create, update: update } };
  9. I am developing my own login textfield within phaser. what is the best way to listen on all the keyboard keys? From the examples, I know you can do something like this : game.input.keyboard.isDown(Phaser.Keyboard.LEFT) Though, it is not elegant to use this for every keycode. any advice?