I need a strategy for developing graphics for the Cocos2d-iPhone project

My little game project is a physics-based platform created using Chipmunk (via SpaceManager) in Cocos2d.

I wanted to be slightly different from the typical tile level design, so I create levels as SVG files in Illustrator, which I then process to create terrain, platforms, spawn points, etc. etc. It works pretty well, and I feel that I can be as creative as I want with such a level design.

However, this approach only creates the body and shape of the chipmunk. It doesn't help me when it comes to creating graphics for things like landscape.

So, to illustrate what I'm talking about, the basic level would look a little something like this (reduced) alt text http://www.tomelders.com/bin/leveleg.jpg

The gray area will represent the landscape.

My first thought was to trace these levels in Photoshop and cut them into 512x512 png, which could then be overlaid on top of the physical layer. But it instinctively sounds like a very inefficient way to go.

The guys behind Rolando have made a super simple approach that works well for them.

alt text http://www.handcircus.com/wp-content/uploads/2008/06/rolando_screen_b.jpg

But I would like to talk a little more about my levels, almost similar to what they achieved in MX Mayhem alt text

, , , , , .

, : - - - , , . Cocos2d TMXTileMaps. , , , - , , , .

.

PS: , - , : ? , , .

+3
1

- ? Cocos2d , . . 512x512, , , , , , , - MX Mayhem . ( , , MX Mayhem.)

, , :

- (CGContextRef) createBitmapContextOfSize:(CGSize) size {
    CGContextRef    context = NULL;
    CGColorSpaceRef colorSpace;
    void *          bitmapData;
    int             bitmapByteCount;
    int             bitmapBytesPerRow;

    bitmapBytesPerRow   = (size.width * 4);
    bitmapByteCount     = (bitmapBytesPerRow * size.height);

    colorSpace = CGColorSpaceCreateDeviceRGB();
    bitmapData = malloc( bitmapByteCount );
    if (bitmapData == NULL) {
        fprintf (stderr, "Memory not allocated!");
        return NULL;
    }
    context = CGBitmapContextCreate (bitmapData,
                                     size.width,
                                     size.height,
                                     8,      // bits per component
                                     bitmapBytesPerRow,
                                     colorSpace,
                                     kCGImageAlphaPremultipliedLast);
    CGContextSetAllowsAntialiasing (context,NO);
    if (context== NULL) {
        free (bitmapData);
        fprintf (stderr, "Context not created!");
        return NULL;
    }
    CGColorSpaceRelease( colorSpace );
    return context;
}

- (UIImage *)drawLevelImage {

    UIImage *gfx = [UIImage imageNamed:@"gfx.png"];
    CGContextRef myBitmapContext = [self createBitmapContextOfSize: CGSizeMake(1024,1024)];
    //  Preserve alpha
    CGContextClearRect (myBitmapContext, CGRectMake(0,0,1024,1024));

    //  Step through your shapes here, and whenever you need to draw something out of your gfx:
    CGImageRef _imageRef = CGImageCreateWithImageInRect(gfx.CGImage, sourceImageRect);
    CGContextDrawImage(myBitmapContext, destinationImageRect, _imageRef);
    CGImageRelease(_imageRef);
    //  The above could be sped up by caching the image refs if you use them more than once.

    UIImage *result = [UIImage imageWithCGImage: CGBitmapContextCreateImage(myBitmapContext)];
    CGContextRelease( myBitmapContext );
    return result;
}
+2

Source: https://habr.com/ru/post/1755177/


All Articles