Jump to content

A few typescript issues; "input.pointerOver()" and "input.onDown.add" correct usage?


huggybear
 Share

Recommended Posts

Newbie programmer here using phaser for one of my uni assignments! I'm building a side-scrolling oldschool Adventure game.

 

Question 1: What is the correct usage of input.poiterOver()?

 

I have multiple sprites defined on a class Level1.ts basically the usage I'm after is you roll over a mouse on the sprite, it displays the sprite name and you roll-off and the name should disappear. It seems like you cannot do this with multiple sprites in the same context?

 

It will work for ONE sprite (the last sprite called in update() but not any others. What gives?

 

I've encapsulated the sprites as follows:

 

-all sprites are created in create()

statue = this.game.add.sprite(330, 162, "statue");statue.inputEnabled = true;innkeeper = this.game.add.sprite(1035, 228, "innkeeper");innkeeper.inputEnabled = true;

-then their behavior sits in their own method: (its the same for all sprites)

npcInkeeper() {            //innkeeper.            if (innkeeper.input.pointerOver()) {                this.onOverNPC(innkeeper, "Innkeeper");                this.game.input.onDown.add(this.dialogInnkeeper, this.npcInkeeper, 1);            }            else if (!innkeeper.input.pointerOver()) {                this.onOutNPC_name();            }            switch (counter_innkeeper) {                case 1:           //blah blah blah more code 

and finally in the update() method they are called to update by name. So how do you get this to work for multiple sprites?

 

Question 2: "this.game.input.onDown.add" Is this the best method for a one-off call from mouse? Why can it only be used once on one sprite before going inactive?

 

Same code as above.. Essentially after you roll over a sprite to reveal its name I'm using input.onDown.add to call its dialog method to start once you click. It's important I use one-click here because my dialog system is very hacky (ie: it triggers a counter and then a switch/case displays dialog based on the counter timer) I'm sure there's a better way to do this but all of the mouse methods in phaser were driving me nuts (doensn't appear to be any "onclick" method) only methods that spam ondown calls.

 

The problem? You can apparently only use "input.onDown.add" once. It works on one sprite and then appears to go inactive to being triggered again?

 

I've tried to call removeAll and Dispose on it per the Docs, but to no avail. I've also tried giving it a context (refer to code above) (this.npcInkeeper) to each sprite and also tried giving it a execution priority number. So is there anyway to reset the method?

 

I'm definitely open to suggestions to change stuff. As I've said there doesn't appear to be a way to use a traditional JS .onclick method in phaser if not accessing the DOM (I may just not know the correct way to do it though) if anyone knows how to use it in regards to a phaser.sprite I'm all ears.

 

 

Link to comment
Share on other sites

Okay I've answered my own questions Turns out...because I'm calling a local method that HIDES npc names... it is constantly being called globally (when mouse isn't over) of the names to be hidden and overwriting other calls from sprites to DISPLAY name. That makes sense. 

 

EDIT:::

 

input.onDown.add is still playing up. It won't call more than once?

 

How do you call something onClick so that it sends one call to a method regardless if you've clicked the mouse 20 times? and upon executing still lets you click it later on...?

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...