cruseyd Posted October 11, 2018 Share Posted October 11, 2018 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. Link to comment Share on other sites More sharing options...
samme Posted October 11, 2018 Share Posted October 11, 2018 Each game object receives a drop event as well, you can use that instead. Link to comment Share on other sites More sharing options...
cruseyd Posted October 13, 2018 Author Share Posted October 13, 2018 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 More sharing options...
cornstipated Posted October 13, 2018 Share Posted October 13, 2018 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 More sharing options...
samme Posted October 13, 2018 Share Posted October 13, 2018 11 hours ago, cruseyd said: 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). It worked for me in http://labs.phaser.io/edit.html?src=src/input\zones\drop zone.js. Link to comment Share on other sites More sharing options...
cruseyd Posted October 14, 2018 Author Share Posted October 14, 2018 Yeah I finally got it to work as I would expect. I think I wasn't clearing my browser cache correctly or something. Thanks for the input all. Link to comment Share on other sites More sharing options...
Recommended Posts