【发布时间】:2012-02-28 10:41:12
【问题描述】:
好吧,我用 UIKit 创建了一个游戏,但我遇到了一些性能问题,所以我决定使用 Cocos2D。我想使用这个代码一个 cocos2D,但我无法做到:
- (CGPoint)randomPointSquare {
CGRect frame = [[self view] frame];
//CGFloat rand_x = ((float)arc4random() / (float)UINT_MAX) * (float)_window.frame.size.width;
NSInteger side = arc4random() / (UINT_MAX/4);
CGFloat offset = 0;
switch(side) {
case 0: /* top */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width;
return CGPointMake(offset, -10);
case 1: /* bottom */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.width;
return CGPointMake(offset, frame.size.height-150);
case 2: /* left */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.height;
return CGPointMake(-10, offset);
default:
case 3: /* right */
offset = ((float)arc4random() / (float)UINT_MAX) * (float)frame.size.height;
return CGPointMake(frame.size.width+200, offset);
}
}
-(void) createNewImage {
UIImage * image = [UIImage imageNamed:@"abouffer_03.png"];
imageView = [[UIImageView alloc] initWithImage:image];
[imageView setCenter:[self randomPointSquare]];
}
有人可以尝试翻译此代码以在 cocos2D 中使用它。谢谢。对不起我的英语我是法国人:/
【问题讨论】:
-
您似乎尝试添加具有随机中心点的图像。在 Cocos2D 中,你应该看看 CCSprite 类,记住 Cocos2D 中的坐标不是左上原点。
标签: iphone xcode uikit cocos2d-iphone