1
我有22張圖片... 11(rightwall1,rightwall2,rightwall3等),其他11(leftwall1,leftwall2,leftwall3等)xcode的CGPoint arc4random不工作
我把每一個ontop的的另一種方法是將它們的y值設置爲之前的牆壁y值加上牆壁的高度(所有牆壁都是相同的高度)。
這工作正常!現在
,我試圖用arc4random設置x的值,這樣他們就活蹦亂跳在一定範圍內的地方......
右壁完美,但左側牆壁,其中一些工作但其中大部分沒有顯示在屏幕上。
我手動將x值設置爲-15,它出現在屏幕上,並且低於arc4random允許的值。
我能想到的唯一問題是我正在減去左牆的錯誤?
下面是設置牆位置的代碼,我在整個項目中沒有其他代碼。
-(void)awakeFromNib {
rightWall1.center = CGPointMake(((arc4random()%75)+330), (460-((rightWall1.frame.size.height)/2)));//460 = bottom of screen
rightWall2.center = CGPointMake(((arc4random()%75)+330), ((rightWall1.center.y)-(rightWall2.frame.size.height)));
rightWall3.center = CGPointMake(((arc4random()%75)+330), ((rightWall2.center.y)-(rightWall3.frame.size.height)));
rightWall4.center = CGPointMake(((arc4random()%75)+330), ((rightWall3.center.y)-(rightWall4.frame.size.height)));
rightWall5.center = CGPointMake(((arc4random()%75)+330), ((rightWall4.center.y)-(rightWall5.frame.size.height)));
rightWall6.center = CGPointMake(((arc4random()%75)+330), ((rightWall5.center.y)-(rightWall6.frame.size.height)));
rightWall7.center = CGPointMake(((arc4random()%75)+330), ((rightWall6.center.y)-(rightWall7.frame.size.height)));
rightWall8.center = CGPointMake(((arc4random()%75)+330), ((rightWall7.center.y)-(rightWall8.frame.size.height)));
rightWall9.center = CGPointMake(((arc4random()%75)+330), ((rightWall8.center.y)-(rightWall9.frame.size.height)));
rightWall10.center = CGPointMake(((arc4random()%75)+330), ((rightWall9.center.y)-(rightWall10.frame.size.height)));
rightWall11.center = CGPointMake(((arc4random()%75)+330), ((rightWall10.center.y)-(rightWall11.frame.size.height)));
leftWall1.center = CGPointMake(((arc4random()%75)-60), (460-((leftWall1.frame.size.height)/2)));
leftWall2.center = CGPointMake(((arc4random()%75)-60), ((leftWall1.center.y)-(leftWall2.frame.size.height)));
leftWall3.center = CGPointMake(((arc4random()%75)-60), ((leftWall2.center.y)-(leftWall3.frame.size.height)));
leftWall4.center = CGPointMake(((arc4random()%75)-60), ((leftWall3.center.y)-(leftWall4.frame.size.height)));
leftWall5.center = CGPointMake(((arc4random()%75)-60), ((leftWall4.center.y)-(leftWall5.frame.size.height)));
leftWall6.center = CGPointMake(((arc4random()%75)-60), ((leftWall5.center.y)-(leftWall6.frame.size.height)));
leftWall7.center = CGPointMake(((arc4random()%75)-60), ((leftWall6.center.y)-(leftWall7.frame.size.height)));
leftWall8.center = CGPointMake(((arc4random()%75)-60), ((leftWall7.center.y)-(leftWall8.frame.size.height)));
leftWall9.center = CGPointMake(((arc4random()%75)-60), ((leftWall8.center.y)-(leftWall9.frame.size.height)));
leftWall10.center = CGPointMake(((arc4random()%75)-60), ((leftWall9.center.y)-(leftWall10.frame.size.height)));
leftWall11.center = CGPointMake(((arc4random()%75)-60), ((leftWall10.center.y)-(leftWall11.frame.size.height)));
}
(arc4random()%75)
回報數字! HAHAHHAHAHAHAHAHHAHAHAAH – 2011-05-30 17:39:54儘管仍然沒有工作,問題是當處理負arc4random值你不能使用整數你必須使用浮動..如果減去你不能只減去你必須添加arc4random乘以負1 float值。這是因爲arc4random使用我假設的模... – 2011-05-31 04:52:57
arc4random返回無符號值。使用%限制範圍。你不需要浮點數 - 只是在%之後的有符號整數。 – 2011-05-31 11:53:35