Doug

Members
  • Content count

    52
  • Joined

  • Last visited

Everything posted by Doug

  1. Doug

    Destroying a matter.js rectangle body

    Just to follow up on this, I can confirm that @rgk was right. I changed the code to the following and it all works. this.matter.world.remove(this.wireRect); Thanks again
  2. Hi all I'm creating a matter.js rectangle body with the following code: let wireRect = this.matter.add.rectangle(w.x, w.y, this.wireLength, 10, { restitution: 0.9, isSensor: true, angle: angle }); I then later need to remove it from the game. wireRect.destroy(); returns an error "wireRect.destroy is not a function". I have another game in which I am using this.matter.add.image(XXX) and the .destroy() method works fine on those. So I tried: this.matter.world.remove(this.matter.world, wireRect); That doesn't seem to work either. I can see matter.body documentation https://photonstorm.github.io/phaser3-docs/MatterJS.Body.html, but can't see how I would find the correct destroy method for it. Any ideas welcome please! Thanks
  3. Doug

    UI Elements on Phaser 3

    I would probably avoid trying to create the login form etc within Phaser. As @snowbillr has hinted at, this would not be all that easy and you're going to need a workaround. Maybe a better approach would be to create an HTML form within a div with a background so that it looks pretty and as if it's a part of the game, but is actually just pure html, css, JS etc and then create or show the Phaser game instance after the login has been processed.
  4. Doug

    Destroying sounds - best practice

    Thanks very much @samme - I am actually using the latest version of Phaser, but I just had another look at my code. It's pretty complicated in there now and it looks like there was one instance where I wasn't destroying the game properly, but just closing the modal. I've amended it now and so far it appears to have done the trick. So I'll do some more testing. Thank you and sorry for wasting your time if it was this.
  5. Hi all I am using Angular 4 and creating an interface which has a number of games. They load in a modal (i.e. no page refresh/change) and I then destroy them with this.phaserGame.destroy(true); I have background audio that I am playing with the following: preload () : void { this.load.audio('bg', [ this.p('audio/bg.mp3'), this.p('audio/bg.ogg') ]); } this.p() just gets the relative path. create () : void { this.sound_bg = this.sound.add('bg', { loop: true }); } When I destroy and reload the game, the background audio object seems to still be in the DOM and plays over itself on second game launch. I've had a look through the documentation and tried removeByKey() remove() and destroy() in the BaseSoundManager() namespace just before destroying the game. None of these seem to solve the problem though. What is best practice for completely destroying sounds please? Thank you!
  6. Doug

    Destroying sounds - best practice

    @rich Sorry to bother you, but I'm still struggling with this one and it's causing me a lot of headaches. What is the best way to completely remove sound from the DOM please? Thanks!
  7. Doug

    onkeyup event (onUp)

    You're most welcome. I assume you've found the documentation here too: https://photonstorm.github.io/phaser3-docs/list_namespace.html Between the labs and the docs you should have everything you need. Enjoy! It's a great framework.
  8. Doug

    Destroying a matter.js rectangle body

    You are a legend, thanks. I can replicate this working in the example page you sent too Will have a go at implementing in my code as soon as I have a chance. Thanks very much! Greatly appreciated.
  9. Doug

    Hi Rich.  @rgk mentioned that you might be able to please add a "patron" badge to my forum profile?  Thanks very much!

  10. Doug

    Destroying a matter.js rectangle body

    Thanks very much. However, the objects still accept collisions etc and also still show up in debug mode. Have you had this working successfully? Just out of interest, how did you get the "Phazer patron" badge to display (I am a patron, but it's not showing for me)?
  11. Doug

    onkeyup event (onUp)

    Hi Josh I think you're looking for this: http://labs.phaser.io/edit.html?src=src\input\keyboard\keydown.js You just replace `keydown` with `keyup`. e.g. this.input.keyboard.on('keyup_A', function (event) { console.log('Hello from the A Key!'); }); I hope this helps and let me know how you get on D
  12. Doug

    Rotation of arcade physics body

    No problem at all. I really appreciate that you tried.
  13. Hi Forgive me if I've missed this, but I can't find it in any of the documentation. Is there a way to specify the the rotation of an arcade physics body? I can rotate the game object image, but that has no effect on the physics body. I would have expected a .setAngle or .setRotation method to be available on Phaser.Physics.Arcade.Body. Seems such a simple one to miss, but I keep needing this and having to use matter, which is just a little more fiddly. Thank you!
  14. Doug

    Rotation of arcade physics body

    Great thank you. Will do.
  15. Doug

    Rotation of arcade physics body

    Thanks, that's really kind of you. Just did the same to check it and it still fails here. It rotates the game object, but not the physics body. let t = this.physics.add.sprite(200, 200, 'sprites', 'windSock_0000'); t.angle = 30;
  16. Doug

    Rotation of arcade physics body

    Thanks. I tried this, but it doesn't work. I tried the following: let t = this.physics.add.sprite(100, 100, 'sprites', 'windSock_0000'); t.body.rotation = 1; ...and let t = this.physics.add.sprite(100, 100, 'sprites', 'windSock_0000'); t.body.angle = 30; Interestingly it doesn't give an error. It just does nothing. I also tried with image and staticImage gameobject types. Do you think this is maybe a bug?
  17. Doug

    Video game object

    Hi All Forgive me if I've missed this, but I can't seem to find any examples or reference to being able to create video game objects / textures. Is this possible please? I am thinking of mp4 or ogg video playing on a game object within the game. Mainly for use in things like interactive product tours etc. I note that the Phaser.Device namespace has a "video" member. I also note that Rich mentioned the video.OnComplete event handler in one of his posts too. So I am wondering if there is support for actual playback too? Thanks very much!
  18. Doug

    Resetting a scene

    Hi All I couldn't find a method to restart / reset a scene. Anyone know if there is one please? Or if there is a better way to do this. Thanks!
  19. Doug

    Animation pivot points

    Update: Andreas at Code And Web pointed me to this: https://github.com/photonstorm/phaser/issues/3288#issuecomment-369294565
  20. Doug

    Animation pivot points

    Hi all I've got an animation of a running ninja (original hey). Sprite sheets attached. I am doing the following in my code: Preload function: this.load.atlas('sprites', this.p('Sprites.png'), this.p('Sprites.json')); Create function: this.ninja = this.physics.add.sprite(this.gameWidth/2, this.gameHeight/2, 'sprites', 'stand').setCollideWorldBounds(true); let runConfig = { key: 'run', frames: this.anims.generateFrameNames('sprites', { prefix: 'run', start: 1, end: 7, zeroPad: 0 }), repeat: -1, frameRate: 5 } this.anims.create(runConfig); this.ninja.play('run'); I am using texturepacker (https://www.codeandweb.com/texturepacker) to create the sprite sheet as a Phaser3 spritesheet. I have set the pivot points for each frame to be on the ninja's chin so that the head is always still when he is running. When I run the game the character jolts left and right as if it is ignoring the pivot points that I've set in texture packer. Is this a bug or am I missing something obvious please? Thanks so much! Sprites.json
  21. Yeah, I was very keen NOT to eject the project because it makes things a lot more complicated. I did manage to get it working via that route by making some changes to the webpack config file that gets generated when you eject the project. However, it wasn't much fun working with the project once ejected. I ended up NOT ejecting the project but just including the phaser JavaScript file in the "scripts" section of .angular-cli.json. Then in the component where I use phaser I added: declare var Phaser: any; I think that was everything I did. It works a treat and means I can easily update the phaser JavaScript file by just replacing it rather than using npm as Rich iterates the updates and fixes bugs etc. I hope that helps and let me know if I missed anything.
  22. Hi all I'm using Angular4 with Phaser 3 beta 20. I need to have separate classes for the Game Scenes so that I can use different game scenes any time I wish. I need to be able to call a function in the parent component that affects the parent component variables. This is probably a totally newbie question so please forgive me, but it's stumped me for the moment on how the scope works. Please see the following code: import { Component } from '@angular/core'; import Phaser from 'phaser'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) export class AppComponent { phaserGame: Phaser.Game; carrot: any; preloadStatus: string = "Preloading"; config: any; gameScene: Phaser.Class; getScene() : any{ return { Extends: Phaser.Scene, initialize: function GameScene(config) { Phaser.Scene.call(this, config); }, preload: function () { this.load.image('carrot', 'assets/carrot.png'); console.log("Phaser game loading done"); this.FromInGame(); }, create: function () { this.carrot = this.add.image(400, 300, 'carrot'); }, update: function () { this.carrot.x += .2; } } } constructor() { let theScene = this.getScene(); theScene.FromInGame = this.FromInGame; this.gameScene = new Phaser.Class(theScene); this.config = { type: Phaser.CANVAS, parent: 'phaser-example', scene: this.gameScene }; this.phaserGame = new Phaser.Game(this.config); } FromInGame() : void{ console.log("called from in game"); this.preloadStatus = "Preload DONE!"; } } I need the FromInGame() function to be fired from the Scene's preload() function, which it is. However, in the FromInGame() function "this" clearly references the Scene because "theScene.FromInGame = this.FromInGame;" is setting it as a function on the Scene. Therefore when executing "this.preloadStatus = "Preload DONE!";" it adds a property preloadStatus with a value "Preload DONE!" to the Scene and rather than updating the this.preloadStatus in the Angular component. Any ideas how I would achieve this please? Thank you very much in advance. D
  23. Hi @LordLants - I did get it working, but I took a rather unconventional route to do it in the end. I'm using game classes so that I can keep the games modular. I pass the context into the class constructor and then set a local variable to store that context. The following is cut down, but gives the idea: export class GAME_SpaceShooter extends (Phaser.Scene as { new(config): any; }) { constructor ( config, context ) { super(config); this.context = context; } sendGameEvent(gameEvent: string) : void { this.context.gameEvent.fire(gameEvent); } } I then have an interface as follows based on this article: import { Injectable } from '@angular/core'; import { Observable } from 'rxjs/Observable'; import {Broadcaster} from './broadcastEvent'; @Injectable() export class GameEvent { constructor(private broadcaster: Broadcaster) {} fire(data: string): void { this.broadcaster.broadcast(MessageEvent, data); } on(): Observable<string> { return this.broadcaster.on<string>(MessageEvent); } } I import the interface into my main page class and subscribe to the gameEvent: ... import { GameEvent } from '../../interfaces/gameEvent'; @Component({ selector: 'app-game', templateUrl: './game.component.html', styleUrls: ['./game.component.css'] }) export class GameComponent implements OnInit { constructor( public gameEvent: GameEvent ) { } getGameStartDataProcessed(response: any, allOk: Boolean): void {//this is called after the XHR returns some app specific data from the server this.gameEventSubscribe = this.gameEvent.on().subscribe(eventName => { switch (eventName) { case 'eventId1': //do stuff break; case 'eventId2': //do other stuff break; default: break; } }); } } This works fine for me. I think I got everything in the description above, but let me know if you have any problems. Good luck!
  24. Doug

    Adding tween targets to existing tween

    Thanks, that's great to know and much appreciated.
  25. Hi All I'm writing a basic platformer which has prizes that I'd like to be undulating in scale. The prizes are generated dynamically as the game progresses. I am using the following tween for this, newly assigning the tween to each new prize as it is created: this.tweens.add({ targets: [scObjCreated], scaleX: '-=.2', scaleY: '-=.2', duration: 700, ease: 'Sine.easeInOut', repeat: -1, yoyo: true }); However, this seems inefficient as I know that you can have one tween with multiple targets, so having loads of tweens that all do the same thing seems like poor practice. I tried assigning the tween to a variable as follows: this.MyTween = this.tweens.add({ targets: [scObjCreated], scaleX: '-=.2', scaleY: '-=.2', duration: 700, ease: 'Sine.easeInOut', repeat: -1, yoyo: true }); ...and then pushing the newly created prize objects to the "targets" array as follows: this.MyTween.targets.push(myNewObject); However, this doesn't seem to do anything. Is there a way to do this please? Thank you!