【发布时间】:2011-11-11 07:01:26
【问题描述】:
我想在每 5 秒后丢弃一些对象。我的问题是,最先出现在屏幕上的动物会掉下来,但之后的动物不会掉下来,它们会粘在原来的位置上。
我丢弃动物的代码是:
-(void)dropAnimal
{
[self performSelector:@selector(dropAnimal) withObject:nil afterDelay:5];
prevojectIndex=objectIndex;
prevIndex=currentIndex;
float padding = sw*128/768;
float x = (float)(arc4random()%(int)(sw-padding*2))+padding;
if([SpritesARRAY count]>0)
{
objectIndex=arc4random()%[SpritesARRAY count];
object=[SpritesARRAY objectAtIndex:objectIndex];
object.falling = YES;
currentIndex=arc4random()%[animalsArray count];
[object initWithSpriteFrameName:[animalsArray objectAtIndex:currentIndex]];
object.position = ccp(x, sh*31/32-self.position.y);
objectsDictionary=[NSMutableDictionary dictionary];
[objectsDictionary setObject:object forKey:[[NSNumber numberWithInt:objectIndex] stringValue]];
[objectsDictionary retain];
[SpritesARRAY removeObjectAtIndex:objectIndex];
[self animateAnimal];
}
}
-(void) animateAnimal
{
FallAnimal *CurObject=[objectsDictionary objectForKey:[[NSNumber numberWithInt:objectIndex] stringValue]];
[CurObject runAction:[CCMoveTo actionWithDuration:2 position:CGPointMake(CurObject.position.x,90)]];
[CurObject release];
}
【问题讨论】:
标签: objective-c cocos2d-iphone xcode4.2