Search code examples
iosc4

Cross-fade or dissolve between two C4Images


How would I do some sort of animation or transition between two C4Images?

I have a setup like this:

C4Image * img1 = [[C4Image alloc] initWithRawData:rawData width:width height:height];
C4Image * img2 = [[C4Image alloc] initWithRawData:rawData width:width height:height];

[self.canvas addImage:img1];
// insert magic here to trigger transition
[self.canvas addImage:img2];

Solution

  • The easiest way to do a transition is:

    image1.animationDuration = 1.0f;
    image1.image = image2;
    

    You can find a snippet here that crossfades an image to a new image 1 second after launching the app:

    https://gist.github.com/C4Code/5074430