c++windowscocos2d-xccspriteuser-data

Cocos2d C++ Identify CCSprites with UserData?


I am stuck in my Game cause I have to much Sprites in CCArrays. I identify the function of the Sprite on it's Tags, but it's not working, cause I only can use Ints as Tag. So I decided to make UserData like this:

int* nums = new int(2);
background->setUserData((void*)nums);

int* data = (int*)background->getUserData();
if(data == 2){  //this line makes the error C2446
    //do some code
}

I need some way to identify my sprites that better than tags? How do I get the UserData to work? Is there another good way to do it?


Solution

  • Try to dereference the pointer:

    if(*data == 2){  //this line makes the error C2446
        //do some code
    }