Ninjadoodle Posted September 14, 2014 Share Posted September 14, 2014 Hi guys I'm trying to figure out how to get the name of a sprite I just clicked/tapped. in Flash, I would use something like event.target.name, to get the name of the sprite. I tried different ways of writing this up in Panda, but can't seem to get the right syntax. Thank you heaps for any help! Quote Link to comment Share on other sites More sharing options...
Sebi Posted September 14, 2014 Share Posted September 14, 2014 Just like in the prior topic:function doSomething( mousedata ) { console.log( this, mousedata );};ninja.click = ninja.tap = doSomething.bind(ninja);ninja.interactive = true;Now "this" inside the click/tap callback refers to the sprite. Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted September 14, 2014 Author Share Posted September 14, 2014 Thank again!! I've been playing around with the code a bit and found that ... if (event.target == ninja1) {console.log('You clicked ninja 1');} else if (event.target == ninja2) {console.log('You clicked ninja 1');} ... also works. The only thing I can't seem to get, is the actual printout of the objects name. all I get in the console is ... >class >object Quote Link to comment Share on other sites More sharing options...
Sebi Posted September 14, 2014 Share Posted September 14, 2014 I'm not sure what you mean by "name". Well you can't display the name of the variable, only its value.function clickHandler() { console.log("You clicked " + this.name);};var ninja1 = new game.Sprite( ... );ninja1.name = "Ninja 1";ninja1.click = ninja1.tap = clickHandler.bind(ninja1);ninja1.interactive = true;Something like that. Just give all your sprites a name property.But maybe I just don't understand what you really want to achieve. Ninjadoodle 1 Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted September 15, 2014 Author Share Posted September 15, 2014 Yeah, I was expecting to be able to print out the name of the variable. Thank you for clearing that up ( I have a lot to learn ). I'm used to working with flash and the ide, and this process is a little different (I'm starting to get hang of it tho). This is definitely all I need to get my level working, so thank you heaps for all you help Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.