سؤال

When I run the "Image Property" example, unmodified, the images have lost their colour (unlike in the video accompanying the example). Any idea what's going on?

Update: I realized that it is only the included C4 images that have this problem (C4Sky.png and C4Table.png).

هل كانت مفيدة؟

المحلول

The issue persists. There seems to be a bug with the image property of C4Image.

Error seen with image code

The solution is to use a pointer to the C4Image you wish to see and then include whichever C4Image the pointer is pointing to onto the canvas. Be sure to remove the old image from the canvas. Using an object comparison removes the need for an extra boolean variable.

    #import "C4Workspace.h"

    @implementation C4WorkSpace {
        //define 2 invisible images
        C4Image *i1, *i2;
        //define a pointer to a selected image
        C4Image *visibleImage;
    }

    -(void)setup {
        i1 = [C4Image imageNamed:@"C4Sky.png"];
        i2 = [C4Image imageNamed:@"C4Table.png"];

        visibleImage = i1;

        i1.center = i2.center = self.canvas.center;

        [self.canvas addImage:visibleImage];
    }

    -(void)touchesBegan {
        [self.canvas removeObject:visibleImage]; // remove old image

        // see what the pointer is pointing to and update accordingly
        if (visibleImage == i1)
            visibleImage = i2;
        else    
            visibleImage = i1;

        // add the newly referenced C4Image to canvas
        [self.canvas addImage:visibleImage]; 
    }

    @end

Here a link to the gist where I'll keep this code: https://gist.github.com/drart/5695449

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top