Jump to content

Search the Community

Showing results for tags 'signals'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • HTML5 Game Coding
    • News
    • Game Showcase
    • Facebook Instant Games
    • Web Gaming Standards
    • Coding and Game Design
    • Paid Promotion (Buy Banner)
  • Frameworks
    • Pixi.js
    • Phaser 3
    • Phaser 2
    • Babylon.js
    • Panda 2
    • melonJS
    • Haxe JS
    • Kiwi.js
  • General
    • General Talk
    • GameMonetize
  • Business
    • Collaborations (un-paid)
    • Jobs (Hiring and Freelance)
    • Services Offered
    • Marketplace (Sell Apps, Websites, Games)

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Website URL


Twitter


Skype


Location


Interests

Found 6 results

  1. Hi, I'm looking for an explanation for the following behaviour: I have a class "Main" extending Phaser.State, a class "Emitter" and a class "Receiver" extending Phaser.Sprite If I dispatch a signal from "Emitter" and listen to it in "Receiver" everything works as expected or to be more precise: "this.game" has the object "App" assigned. If I reload the state and dispatch again the signal two things happen: The listener receives the signal two times. The 1st time "this.game" is null, the 2nd time "this.game" contains again the object "App" (please have a look at the screenshot showing the console output) Does anybody have an explanation for this behaviour? Thanks, Boris The code (TypeScript) export class Game extends Phaser.Game { constructor() { super(480, 640, Phaser.AUTO, 'content', null); this.state.add('Main', Main, true); console.log("Game started"); } } class Main extends Phaser.State { private emitter: Emitter; private receiver: Receiver; preload() { this.load.image('logo', 'assets/logo.png'); } create() { this.emitter = new Emitter(this.game); this.receiver = new Receiver(this.game); const rKey = this.input.keyboard.addKey(Phaser.Keyboard.R); rKey.onDown.add(() => { console.log('reload state Main'); this.game.state.start('Main',true,false); }, this); } } class Emitter { // -- Signals static onEventFromEmitter: Phaser.Signal = new Phaser.Signal(); constructor(private game: Phaser.Game) { const spaceKey = this.game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); spaceKey.onDown.add(() => { Emitter.onEventFromEmitter.dispatch(); }, this); } } class Receiver extends Phaser.Sprite { constructor(game: Phaser.Game) { super(game, 0, 0, 'logo'); this.game.add.existing(this); this.subscribe(); } /** * Subscribe to events */ private subscribe(): void { Emitter.onEventFromEmitter.add(() => { console.log('Game object in Receiver, listening to onEventFromEmitter', this.game); }, this); } }
  2. Hey guys, Phaser newbie here, need some help with events. How are people dispatching custom events throughout their games. Let's say for example you have 2 classes. Main and Car. Main adds the Car class. The Main class needs to know when the car is low on petrol to update the UI. So would you use Phaser.Signals to handle this communication, or would you just call a function in the Main class directly from the Car class? Are there plans to improve events in Phaser? I understand events can't be global to the Phaser namespace because we need to support multiple Phaser instances, but couldn't events exist globally inside each World instance? All display objects within the World could dispatch and listen for events. Events could bubble up the display list. Does this sound feasible? Thanks! Matt.
  3. Hey guys, can you point me at any example usage of Phaser Signals which is a bit more in-depth than a 2-liner? Surprised me how few descriptions i found compared how powerful / important feature it is in Phaser, and how many question admittedly coming on this topic. I read the other link i found What i would be curious: 1. example how to implement publish-subscribe / observers with Signals from player's hero to enemy types & vice-versa, or 2. examples on a general architecture / best practices for broader usage on custom events in a Phaser game, any case study etc. I'm sure i'll come out my own solutions soon, but would really curious how you are using, as relying fully on events are becoming widespread in the wider webdev world, i.e. Flux, Redux Thanks!
  4. Hey Everyone, I hope someone could help me with this, or if anyone has run into this issue before. I've noticed when I add a signal to an extended sprite, it will be executed immediately. Has anyone run into this issue before? var Card = function(game, x, y, data){ Phaser.Sprite.call(this, game, x, y, 'cardFront'); this.cardName = data.cardName || null; // String this.scale.setTo(0.15,0.15);};Card.prototype = Object.create(Phaser.Sprite.prototype);Card.prototype.constructor = Card;var card = new Card(this.game, 0, 0, {name:'test'});card.input.useHandCursor = true;card.events.onInputOver.add(highlightCard, this, 0, 'arg1', 'arg2');HighlightCard = function(sprite, pointer, arg1, arg2){ console.log('highlight:', sprite, pointer, arg1, arg2);}; Thank you!
  5. Is it good practice to do the following: this.events.onBloomOver = new Phaser.Signal();; Or should the events property be left for Phaser's own events only? And if it's ok - Since I'm using Typescript, how can I get around Webstorm complaining about Unresolved variable onBloomOver - some sort of Interface?
  6. Signals are a light-weight, strongly typed messaging tool and we use them extensively in our game framework. And we’ve just released our TypeScript implementation for others to benefit from. It’s a conversion of js-signals by Miller Medeiros, which is of course in turn a conversion of AS3-Signals by Robert Penner. You can get TypeScript-Signals from github. If you are unfamiliar with Signals, how they work and how they compare to Events then this short summary is well worth a quick read, but to summarise: A Signal is essentially a mini-dispatcher specific to one event, with its own array of listeners.A Signal gives an event a concrete membership in a class.Listeners subscribe to real objects, not to string-based channels.Event string constants are no longer needed.Signals are inspired by C# events and signals/slots in Qt. I ported over all of the 18 unit tests to TypeScript as well. So you have plenty of examples: from adding a basic listener up to manual binding and dynamic context switching. http://www.photonstorm.com/archives/9826/typescript-signals-released-think-outside-the-event
×
×
  • Create New...