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

  • SEARCH
  • Home
  • 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 8589857
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T23:09:24+00:00 2026-06-11T23:09:24+00:00

I want animate some characters in my game by using a texture sprite/atlas. The

  • 0

I want animate some characters in my game by using a texture sprite/atlas.

The basic idea was to always only load one part of the big atlas image, the part that should be used as the character texture right now.
Is this possible? Or is my thought process wrong?

The following is my code for loading the whole texture. With the row and col arguments I want to specify which part of the atlas I want to use as my texture right now.

- (GLuint) loadTexture:(NSString*)fileName row:(int)row col:(int)col
{
    NSLog(@"Loading image %@", fileName);
    NSLog(@"Texture Part: %d, %d", row, col);
    CGImageRef spriteImage = [UIImage imageNamed:fileName].CGImage;
    if (!spriteImage) {
        NSLog(@"Failed to load image %@", fileName);
        exit(1);
    }

    size_t img_width = CGImageGetWidth(spriteImage);
    size_t img_height = CGImageGetHeight(spriteImage);

    GLubyte * spriteData = (GLubyte *) calloc(img_width * img_height * 4, sizeof(GLubyte));

    CGContextRef spriteContext = CGBitmapContextCreate(spriteData, img_width, img_height, 8, img_width*4, 
                                                   CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);        

    CGContextDrawImage(spriteContext, CGRectMake(0, 0, img_width, img_height), spriteImage);

    CGContextRelease(spriteContext);

    GLuint texName;
    glGenTextures(1, &texName);
    glBindTexture(GL_TEXTURE_2D, texName);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); 

    glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, img_width, img_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spriteData);

    free(spriteData);        
    NSLog(@"Texture successfully loaded!");

    return texName; 
}

Right now I can only load the whole image with this code, so I can only use the original image and not one small part of it to display one step of the animation.

  • 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-11T23:09:25+00:00Added an answer on June 11, 2026 at 11:09 pm

    Watch & look at some of the examples at 71Squared:
    http://www.71squared.com/2009/04/iphone-game-programming-tutorial-5-animation-class/

    It’s correct to load the whole texture, but when drawing you will set the texture verticies to be that of the desired column & row.

    As a quick example:

    GLfloat textureVertices[] = {
        1.0f, 0.0f, //br
        0.0f, 0.0f, //bl
        1.0f, 1.0f, //tr
        0.0f, 1.0f, //tl
    };
    glVertexAttribPointer(attributeTextureCoord, 2, GL_FLOAT, 0, 0, textureVertices);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a game, and I want to be able to animate some of
I want to animate some multiple objects sequentially. As in, one animation should happen
I have implemented game application.In which i want to animate some area of images
i want to use .animate function but i have some problems i want to
I have a few divs that I want to animate using jQuery. However, I
I am using flot to do some graphing and I am trying to animate
I am using Mootools 1.3.1 and I want to animate a div with fx.morph
I want to animate some text in a slow and subtle way. jQuery animations
I want to find a way to animate a whole UIView which contains some
Imagine you want to animate some object on a WinForm. You setup a timer

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.