How to animate images using bitmaps / rgb data in iOS

后端 未结 2 1420
一个人的身影
一个人的身影 2021-01-17 05:21

I\'m programming a game on my iPhone, and I have an image I want to animate, say a walking person in a bitmap. The bitmap changes over time. How do I add the bitmaps to the

相关标签:
2条回答
  • 2021-01-17 06:14

    The most efficient way to load an image sequence is to use PVR-format images and load them as OpenGL textures. PVR images support a variety of formats, including raw 32-bit RGB data.

    I've wrapped up this functionality in a library that gives you a GLImageView and lets you specify a list of filenames which it will efficiently stream into memory and play in sequence:

    https://github.com/nicklockwood/GLView

    Check out the included example and see if it will work for your needs. The documentation includes instructions for creating the images in the right format, etc.

    0 讨论(0)
  • 2021-01-17 06:20

    You can do it with a CAKeyframeAnimation.

    I just wrote this and didn't test it - but should get you on the right path. Load all your frames into an NSArray then set the 'values' of the animation to the frames array.

    NSArray *walkFrames = [[NSArray arrayWithObjects:
               [UIImage imageNamed:@"walk.00000.png"],
               [UIImage imageNamed:@"walk.00001.png"],
               [UIImage imageNamed:@"walk.00002.png"],
               [UIImage imageNamed:@"walk.00003.png"],
               [UIImage imageNamed:@"walk.00004.png"],
               [UIImage imageNamed:@"walk.00005.png"],
               [UIImage imageNamed:@"walk.00006.png"],
               [UIImage imageNamed:@"walk.00007.png"],
               [UIImage imageNamed:@"walk.00008.png"],
               [UIImage imageNamed:@"walk.00009.png"],
               nil] retain];
    
    CAKeyframeAnimation *anim = [CAKeyframeAnimation animation];
    
    anim.keyPath = @"contents";
    anim.duration = 2.f;
    anim.values = walkFrames;
    anim.calculationMode = kCAAnimationLinear;
    anim.repeatCount = HUGE_VAL;
    
    [myView addAnimation:anim forKey:@"myFlipAnimation"];
    
    0 讨论(0)
提交回复
热议问题