你对iphone有什么看法?
在我的游戏中,鸟儿在一个框架内飞行,但我只能让它们朝两个不同的方向飞行。如果有两只鸟,它们会飞向两个不同的方向。如果有三只鸟,其中两只朝一个方向飞,另一只朝另一个方向飞。我想让这些鸟随机飞向四个不同的方向。右上、右下、左上、左下,这是我的代码你对iphone有什么看法?,iphone,xcode,animation,sdk,direction,Iphone,Xcode,Animation,Sdk,Direction,在我的游戏中,鸟儿在一个框架内飞行,但我只能让它们朝两个不同的方向飞行。如果有两只鸟,它们会飞向两个不同的方向。如果有三只鸟,其中两只朝一个方向飞,另一只朝另一个方向飞。我想让这些鸟随机飞向四个不同的方向。右上、右下、左上、左下,这是我的代码 -(void) AddBirdIntoArray: (int) BirdCount { for(int i=0; i< BirdCount ; i++){ if(appDelegate.enemyselect == 0){ imgBi
-(void) AddBirdIntoArray: (int) BirdCount {
for(int i=0; i< BirdCount ; i++){
if(appDelegate.enemyselect == 0){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImage];
[imgBird[i] setAnimationImages:birdArrayConstant];
}
else if(appDelegate.enemyselect == 1){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagegreenorange];
[imgBird[i] setAnimationImages:birdArrayConstant3];
}
else if(appDelegate.enemyselect == 2){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImageblueyellow];
[imgBird[i] setAnimationImages:birdArrayConstant4];
}
else if(appDelegate.enemyselect == 3){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagebluewhite];
[imgBird[i] setAnimationImages:birdArrayConstant2];
}
else if(appDelegate.enemyselect == 4){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagepinkpurple];
[imgBird[i] setAnimationImages:birdArrayConstant5];
}
else if(appDelegate.enemyselect == 5){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImagebluegreen];
[imgBird[i] setAnimationImages:birdArrayConstant6];
}
else if(appDelegate.enemyselect == 6){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImageorangewhite];
[imgBird[i] setAnimationImages:birdArrayConstant7];
}
else if(appDelegate.enemyselect == 7){
imgBird[i]=[[UIImageView alloc] initWithImage:firstImageredblue];
[imgBird[i] setAnimationImages:birdArrayConstant8];
}
[imgBird[i] setAnimationDuration:1.0];
[imgBird[i] startAnimating];
if(i%2==0){
pos[i]=CGPointMake(-1,1);
}
else{
pos[i]=CGPointMake(1,-1);
}
xvalue = arc4random()%250;
yvalue = arc4random()%250;
CGRect TempRect = CGRectMake(xvalue ,yvalue , 22 , 22);
imgBird[i].frame = TempRect;
[birdImageViewArray addObject:imgBird[i]];
[self addSubview:imgBird[i]];
[imgBird[i] release];
}
[birdArray release];
}
-(void)AddBirdIntoArray:(int)BirdCount{
对于(int i=0;i
我认为这是两个方向向量:
pos[i]=CGPointMake(-1,1);
pos[i]=CGPointMake(1,-1);
其他两个方向是:
pos[i]=CGPointMake(-1,-1);
pos[i]=CGPointMake(1,1);
当然,与基于i%2
的if/else不同,您应该使用基于以下内容的开关:
arc4random()%4
我认为这是你的两个方向向量:
pos[i]=CGPointMake(-1,1);
pos[i]=CGPointMake(1,-1);
其他两个方向是:
pos[i]=CGPointMake(-1,-1);
pos[i]=CGPointMake(1,1);
当然,与基于i%2
的if/else不同,您应该使用基于以下内容的开关:
arc4random()%4
你介意更具体一点吗?如何为arc4random()%4编写if语句?我已经计算出来了,不过谢谢你的回答,肯定会有帮助。你介意更具体一点吗?如何为arc4random()%4编写if语句?我已经找到了答案,不过谢谢你的回答,肯定有帮助