Hi guyz, i have a button sprite i’d like to attach a touch event listener to. . when i click it, i want something to happen, . like execute a getter method to display the property of an array object.
do you have code snippet i could study? Please don’t suggest using CCMenu cause I want to do something at the ‘touch begin’ and ‘touch ended’ functions :)),
You can use bounding box of a particular sprite and make the things happen
if your finger is within the boundary of that sprite the functions will execute
for example
in your .h function declare the touch function
void ccTouchesEnded(CCSet* touches, CCEvent* event);
```
in your .cpp class add a sprite lets say buttonSprite
Now define the touchend function
if(buttonSprite->boundingBox().containsPoint(location))
{
CCLOG(“Button clicked”);
//do your functionalities here
}
}```
Similar way you can make a touchbegin function. ButtonClick will execute when you remove the finger from the sprite in above case.
In case of touchbegin it will work as soon as you touch the sprite
make sure to make your buttonSprite global. You can make in .h class
CCSprite * buttonSprite;
```
and create in .cpp class