【问题标题】:cocos2d - Creating CCSprite in UIKit Applicationcocos2d - 在 UIKit 应用程序中创建 CCSprite
【发布时间】:2012-08-08 14:59:19
【问题描述】:

我有一个普通的 UIKit 应用程序,但我想使用 cocos2d 做一些小工作。我想使用函数glReadPixels,为此我需要一个cocos2d图像-> CCSprite。

我现在在这个问题上工作了 2 天,因为我收到了这个错误:

2012-08-08 16:58:50.673 iBlaulicht 2[11801:16a03] * 由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“ +[ NSString stringWithCString:encoding:]: NULL cString' ** 首先抛出调用堆栈: (0x1f88022 0x1b9bcd6 0x1f30a48 0x1f309b9 0x16050c7 0x62687 0x62589 0x62317 0x86979 0x47c5c 0x2d63 0xdc5a1e 0x222d 0xcfc386 0xcfd274 0xd0c183 0xd0cc38 0xd00634 0x338cef5 0x1f5c195 0x1ec0ff2 0x1ebf8da 0x1ebed84 0x1ebec9b 0xcfcc65 0xcfe626 0x20cb 0x2065) 终止称为抛出异常(lldb)

这是我的代码:

    - (id)initWithImage:(UIImage *)drawnImage{

    if (self == [super init]) {



        CCTexture2D *tex = [[[CCTexture2D alloc] initWithImage:drawnImage resolutionType:kCCResolutionRetinaDisplay] autorelease];
        CCSprite *imageSprite = [CCSprite spriteWithTexture:tex];


        imageSprite.position = CGPointMake(0, 0 );
        [self addChild:imageSprite];



    }


    return self;
}


- (NSArray *)determinePixels{


    for (int y_direction = 0; currentImage.size.height > y_direction; y_direction += 20) {


        for (int x_direction = 0; currentImage.size.width > x_direction; x_direction += 20) {

            Byte pixelColor[4];
            glReadPixels(x_direction, y_direction, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, &pixelColor[0]);

            // Just to test
            NSLog(@"0");
        }
    }

    return 0;
}

感谢您的帮助...谢谢。 克里斯

【问题讨论】:

    标签: iphone cocos2d-iphone ccsprite


    【解决方案1】:

    查看 Ray Wenderlich 关于此主题的帖子;

    http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit

    【讨论】:

    • @ChristianPappenberger 好运吗?
    • 不是真的...你能提供一些示例代码吗?我真的只想要 cocos2d 上下文中的图像。我会很感激你的帮助;)
    • 你使用的是哪个版本的 Coco2D?
    • @ChristianPappenberger 我的荣幸 ;)
    【解决方案2】:

    我自己找到了解决方案!

    我添加了一个 EAGLView 并使用 CCDirector 将其设置为 OpenGL 视图。

    - (id)initWithImage:(UIImage *)drawnImage{
    
        if (self == [super init]) {
    
            EAGLView *glview = [EAGLView viewWithFrame:CGRectMake(0, 0, 250,350)];
    
    
            CCDirector *director = [CCDirector sharedDirector];
            [director setOpenGLView:glview];
    
            CCTexture2D *tex = [[CCTexture2D alloc] initWithImage:drawnImage resolutionType:kCCResolutionRetinaDisplay];
            imageSprite = [KKPixelMaskSprite spriteWithTexture:tex];
    
    
            imageSprite.position = CGPointMake(0, 0 );
            [self addChild:imageSprite];
    
    
    
        }
    
    
        return self;
    }
    

    【讨论】:

      猜你喜欢
      • 2011-07-29
      • 2023-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-21
      • 1970-01-01
      相关资源
      最近更新 更多