我有一个小的方法,我打电话来随着游戏的进行逐渐绘制恒星。下面是代码:`UIView alpha值问题
-(void)stars{
for (int i = 0; i < (ScoreNumber * 3); i++){
int starX = ((arc4random() % (320 - 0 + 1)) + 0);
int starY = ((arc4random() % (640 - 0 + 1)) + 0);
int starSize = ((arc4random() % (1 - 0 + 1)) + 1);
UIView *stars = [[UIView alloc] initWithFrame:CGRectMake(starX,starY, starSize, starSize)];
stars.alpha = (i/5);
stars.backgroundColor = [UIColor whiteColor];
[self.view addSubview:stars];
}
}
明星做节目,而是通过循环它虫子另一个的UIImageView(主角)每次迭代并复位它的位置。此外,阿尔法值似乎根本不起作用,它似乎只使用值1(完整显示)。任何建议(对于新的程序员)将不胜感激。
一旦'i'大于5,alpha就会是1.即使在前4个循环中alpha也被设置为1? – trevorj 2014-09-13 11:18:52
是的,这实际上是我的意图,但是,正如我在下面指出的那样,我做了一个愚蠢的数学监督。 – Frankeex 2014-09-14 11:35:32