• Content Count

  • Joined

  • Last visited

Everything posted by thosakwe

  1. You should be calling this.sound.add, etc. in your create() method. And then just have a click listener that picks a random sound from an array (this should be a member on your class). I have no idea what's in your SoundController class, but calls to "this.sound.add" and "play()" are two different actions. See this gist for what I'm saying:
  2. When you call "this.sound.add(...)," the return object is of type Phaser.Sound.BaseSound. Keep a reference to each of these sounds in your scene class. In fact, keep the sounds together in an array. Then, to pick a song to play, just choose a random index from the array, and call the play() method. Phaser has some utilities for picking a random item, IIRC, but otherwise you can just use Math.random.
  3. Just wanted to expound upon this answer, for anyone who stumbles across this in the future. That second parameter on `` is named "ignoreIfPlaying." If false, whichever animation is currently playing will stop, even if it's the animation you intend to play. If true, then if you're already playing that animation it will continue. It's false by default, so you can omit the second argument entirely. Secondly, `repeat` determines the number of times the animation will play. When you have it as -1, Phaser interprets that as "loop indefinitely." The default value is 0, in which case the animation will play once, and repeat zero times. For more info, see the API docs: And:
  4. I've just started a Phaser tutorial series on YouTube: I'll be sure to try to address some of the listed pending requests, i.e. things like shaders would be good to make a quick tutorial about. P.S. Can I suggest a few tutorial ideas for this list, too?
  5. That's actually a pretty vague question, as it's unclear what you mean by "Angular 6 with Phaser." Which version of Phaser? Are you using a module bundler? What are you trying to do? Embed a Phaser game in an Angular component? Send data from Phaser to Angular? Send data from Angular to Phaser? Use Phaser to cause an Angular component to be rendered? Angular TypeScript, or Angular Dart? Without information, it's hard to really know what to say... That being said, I'm assuming that you're trying to embed a Phaser game within an Angular component. You can pass a <canvas> element in your Phaser game configuration, so if your Angular template has a <canvas>, you can grab a reference to it, and then initialize Phaser. If you download the Phaser TypeScript typings from the phaser3-docs Github repo, then you should be able to use Angular and Phaser in the same project without much hassle. You might, though, need some way to tell Angular to never update your component's state, otherwise a UI update might trigger a recreation of your canvas, and start a whole new game (though you can technically work around this and start specific game states depending on Angular's state).