gpt4 book ai didi

cocoa-touch - 获取 Sprite 在数组 cocos2d 中的位置

转载 作者:行者123 更新时间:2023-12-03 01:09:39 25 4
gpt4 key购买 nike

我需要能够触摸数组中的特定移动 Sprite 并对其执行操作。但是,当我执行 MoveTo 操作时, Sprite 位置不会更新。救命!

数组:

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 的位置实际上并未更新或移动。耶!仅在 Sprite 的原点位置生成。

最佳答案

试试这个:

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

temp = [birdLayer getChildByTag:100];

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

// do stuff...
}

关于cocoa-touch - 获取 Sprite 在数组 cocos2d 中的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11279429/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com