0

我想通过在触摸时替换一个精灵来添加两个精灵。我尝试了以下代码。只有当精灵是水平的时它才能正常工作。如果精灵移动或不水平,如何使其工作。

我正在使用 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);

提前致谢。:)

4

1 回答 1

0

根据您的代码片段,您永远不会设置新的精灵位置。anchorPositionand是相对于transformPosition精灵本身并定义定位和变换的锚点,但不定位精灵本身。该position属性是您正在寻找的。

于 2013-09-03T08:50:09.757 回答