cocoa-touch – 在数组cocos2d`中获取精灵的位置

cocoa-touch – 在数组cocos2d`中获取精灵的位置,第1张

概述我需要能够触摸数组中的特定移动精灵并对其执行 *** 作.但是,当我执行MoveTo *** 作时,精灵位置不会更新.救命! 阵: int numbreds = 7;redBirds = [[CCArray alloc] initWithCapacity: numbreds];for( int i = 1; i<=numbreds; i++){ int xvalue = ((-50*i) + 3 我需要能够触摸数组中的特定移动精灵并对其执行 *** 作.但是,当我执行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的位置实际上没有更新或移动.好极了!仅在精灵的原点位置生成.

解决方法 试试这个:

CCSprite *temp = [CCSprite spriteWithfile:@"taco.png"];temp = [birdLayer getChildByTag:100];if (temp.position.x == location.x) {    // do stuff...}
总结

以上是内存溢出为你收集整理的cocoa-touch – 在数组cocos2d`中获取精灵的位置全部内容,希望文章能够帮你解决cocoa-touch – 在数组cocos2d`中获取精灵的位置所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1000051.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存