잘 UIKit으로 게임을 만들었고 성능 문제가 발생하여 Cocos2D를 사용하기로 결정했습니다.이 코드를 cocos2D로 사용하고 싶지만 할 수 없습니다. 그것은 :Cocos2D에서 UIKit 코드를 사용할 수 없습니다.
- (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.Thank에서 사용이 코드를 번역하려고 수 :/
임의의 중심점이있는 이미지를 추가하려고하는 것 같습니다. Cocos2D에서 Cocos2D의 좌표는 Upper Left Origin이 아니라는 것을 기억하면서 CCSprite 클래스를 살펴보아야합니다. – Franck