Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8624515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:32:53+00:00 2026-06-12T07:32:53+00:00

How do I make a sprite graphic using CoreGraphics in Cocos2d? I’m trying to

  • 0

How do I make a sprite graphic using CoreGraphics in Cocos2d?

I’m trying to make a sprite that uses the graphics that are made with core graphics.

Thanks for any insights and help!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T07:32:54+00:00Added an answer on June 12, 2026 at 7:32 am

    This solved it.

    Answer below is copied from a reply I received on the Game Dev site: https://gamedev.stackexchange.com/questions/38071/how-to-make-a-sprite-using-coregraphics-ios-cocos2d-iphone


    I don’t know cocos2d, so i just can just give you some tricks about CoreGraphics on iOS.

    First, the simple case, if you can create sprite from a UIImage or a CGImageRef.

    /* function that draw your shape in a CGContextRef */
     void DrawShape(CGContextRef ctx)
     {
         // draw a simple triangle
    
         CGContextMoveToPoint(ctx, 50, 100);
         CGContextAddLineToPoint(ctx, 100, 0);
         CGContextAddLineToPoint(ctx, 0, 0);
         CGContextClosePath(ctx);
      }
    
    
        void CreateImage(void)
        {
           UIGraphicsBeginImageContext(CGSizeMake(100, 100));
    
           DrawShape(UIGraphicsGetCurrentContext());
    
           UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    
           UIGraphicsEndImageContext();
    
           // now you've got an (autorelease) UIImage, that you can use to
           // create your sprite.
           // use image.CGImage if you need a CGImageRef
        }
    

    If you need to provide a buffer of data, and create your own CGContextRef :

    CGContextRef CreateBitmapContextWithData(int width, int height, void *buffer)
    {
        CGContextRef ctx;
        CGColorSpaceRef colorspace;
        size_t bytesPerRow;
        size_t bitsPerComponent;
        size_t numberOfComponents;
        CGImageAlphaInfo alpha;
    
        bitsPerComponent = 8;
        alpha = kCGImageAlphaPremultipliedLast;
    
        numberOfComponents = 1;
        colorspace = CGColorSpaceCreateDeviceRGB();
    
        numberOfComponents += CGColorSpaceGetNumberOfComponents(colorspace);
        bytesPerRow = (width * numberOfComponents);
    
        ctx = CGBitmapContextCreate(buffer, width, height, bitsPerComponent, bytesPerRow, colorspace, alpha);
    
        CGColorSpaceRelease(colorspace);
    
        return ctx;
    }
    
    void CreateImageOrGLTexture(void)
    {
       // use pow2 width and height to create your own glTexture ...
       void *buffer = calloc(1, 128 * 128 * 4);
       CGContextRef ctx = CreateBitmapContextWithData(128, 128, buffer);
    
       // draw you shape
       DrawShape(ctx);
    
       // you can create a CGImageRef with this context 
       // CGImageRef image = CGBitmapContextCreateImage(ctx);
    
       // you can create a gl texture with the current buffer
       // glBindTexture(...)
       // glTexParameteri(...)
       // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, buffer);
    
       CGContextRelease(ctx);
       free(buffer);
    }
    

    See Apple documentation for all CGContext functions : https://developer.apple.com/library/mac/#documentation/graphicsimaging/reference/CGContext/Reference/reference.html

    Hope this help.


    End users answer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make a sprite animate in cocos2D . I believe I
Using XNA, I'm trying to make an adventure game engine that lets you make
I am trying to make a sprite follow a bezier curve. I found a
Hey all I'm trying to make a 3d game in with 2d sprite characters.
I'm using AndEngine to make a game. The user creates a sprite when they
I am trying to make a sprite dance according to the beat of a
I have a sprite in my iPhone game, how can make it so that
Basically i'm trying to make a tic-tac-toe game using C++ and SFML2 API. I
I need to create a sprite graphic, I hope that's the right name for
I make a sprite, then add a child sprite. I add a listener to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.