How to add listener to a sprite in cocos2d in android -
i working on cocos2d,and in need of adding listener sprite.my code here
public class gameoverscreen extends cclayer implements keyhandler { public static ccscene scene(difficulty difficulty, long totalscore) { ccscene result = ccscene.node(); ccsprite redeem = ccsprite.sprite("redeem.png");// listener sprite cgsize s = ccdirector.shareddirector().winsize(); redeem.setscale(block.scale*main.scale); redeem.setposition(-1, -1); redeem.setanchorpoint(cgpoint.ccp(-0.7f, -1)); result.addchild(new gameoverscreen(newhighscore, totalscore)); result.addchild(redeem); return result; }
@override public boolean cctouchesbegan(motionevent event) { location = ccdirector.shareddirector().converttogl(cgpoint.ccp(event.getx(), event.gety())); if(cgrect.containspoint((redeem.getboundingbox()), location)){ //action } return true; }
short , simple trick resolve
Comments
Post a Comment