我想通过在触摸时替换一个精灵来添加两个精灵。我尝试了以下代码。只有当精灵是水平的时它才能正常工作。如果精灵移动或不水平,如何使其工作。
我正在使用 cocos2d box2d 物理。
CCLOG(@"Touch Detected");
CGPoint pos=touchedSprite.position;
[touchedSprite removeSelf];
LHSprite *myNewSprite = [loader createSpriteWithName:@"Red_10" fromSheet:@"images" fromSHFile:@"BreakGlassResources" ];
myNewSprite.uniqueName=@"Red_10";
myNewSprite.tag=BRICK;
[myNewSprite transformPosition:ccp(pos.x,pos.y)];
myNewSprite.anchorPoint=ccp(1,0.5);
[myNewSprite registerTouchBeganObserver:self selector:@selector(touchBeginOnSprites:)];
LHSprite *myNewSprite1 = [loader createSpriteWithName:@"Blue_10" fromSheet:@"images" fromSHFile:@"BreakGlassResources" ];
myNewSprite1.uniqueName=@"Blue_10";
myNewSprite1.tag=BRICK;
[myNewSprite1 transformPosition:ccp(pos.x+myNewSprite.size.width,pos.y)];
myNewSprite1.anchorPoint=ccp(1,0.5);
提前致谢。:)