Jump to content

Getting the name of the sprite clicked? (SOLVED)


Recommended Posts

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!

Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 :)

Link to comment
Share on other sites

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.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

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