4

配列内の特定の移動スプライトに触れて、それに対してアクションを実行できる必要があります。ただし、MoveTo アクションを実行すると、スプライトの場所が更新されません。ヘルプ!

配列:

int numbreds = 7;

redBirds = [[CCArray alloc] initWithCapacity: numbreds];

for( int i = 1; i<=numbreds; i++){

    int xvalue = ((-50*i) + 320);
    int yvalue= 160;


    if (i==4)
    { 
        CCSprite *parrot = [CCSprite spriteWithFile:@"taco.png"];

        [birdLayer addChild:parrot];
        [self movement]; //the action that moves the array horizontally
        parrot.position = ccp(xvalue,yvalue);
        parrot.tag=100;

接する

-(void)ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:[touch view]];
location = [[CCDirector sharedDirector] convertToGL:location];


CCSprite *mark = (CCSprite *)[birdLayer getChildByTag:100];

if (CGRectContainsPoint([mark boundingBox], location))
{

    CCLOG(@"YAY!");
}

問題は、CCSprite の場所が実際には更新または移動されないことです。わーい!スプライトの原点位置でのみ生成されます。

4

1 に答える 1

2

これを試して:

CCSprite *temp = [CCSprite spriteWithFile:@"taco.png"];

temp = [birdLayer getChildByTag:100];

if (temp.position.x == location.x) {

    // do stuff...
}
于 2012-07-01T04:07:56.540 に答える