Jump to content

Object Specific Event Handlers


cruseyd
 Share

Recommended Posts

I've noticed a pattern while rifling through the Phaser 3 example code. Events seem to nearly always be handled globally, but the scene input. For example, in the snippet below from the drop zone tutorial, the code defines a handler for a gameObject being dropped into a drop  zone. But what if I have several types of game object which I want to handle being dropped differently? You could put a conditional in the global callback to check what kind of gameObject you're dealing with, or you could give all your gameObjects a callback with the same name (e.g. onDrop(args)), but I feel like there should be a much cleaner solution. Can I define all this functionality in class members for example?

Sorry if I've missed something obvious; the documentation for Phaser 3 seems like it's still relatively new. 

image.png.a29e2d82651cf9774596684fc5ace639.png

Link to comment
Share on other sites

Mmkay, I'm seeing that in the source code which is useful, but I can't seem to get the specific 'drop' event to fire. How does it differ from 'dragend'? Based on the source code it *looks like* a 'drop' has the semantics of a drag ending inside a valid drop zone, but I can't get it to trigger that way either (but I am able to trigger e.g. 'dragenter' which also requires a drop zone). 

Link to comment
Share on other sites

On 10/11/2018 at 8:47 AM, cruseyd said:

but I feel like there should be a much cleaner solution. Can I define all this functionality in class members for example?

    this.input.on('drop', function (pointer, gameObject, dropZone) {

        if(gameObject.myondrop) gameObject.myondrop(pointer,dropZone,whatever)

    });

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

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