I am working with a C4 app, and have created a subclass of C4Shape. I am having trouble accessing the canvas from within the subclass but I'm not sure how to check it, or how to get access to it from another object.

This is the code I have so far:

#import "Platform.h"

@implementation Platform {
    CGPoint o;
    C4Timer *timer;
    int speed;
}

-(void) setup {
    speed = 10;
    [self rect:CGRectMake(0, 0, 100, 100)];

    timer = [C4Timer automaticTimerWithInterval:1.0f/30
                                         target:self
                                         method:@"push"
                                        repeats:YES];
    o = self.center;
}

+(id) platformWithRange:(CGRect)s {
    Platform * bb = [Platform new];
    bb.range = s;
    return bb;
}

-(void) push {
    // check boundaries
    o.x-= speed;
    if( 0 >= o.x - 50 ) {
        o.x = range.size.width;
    }
}
@end
有帮助吗?

解决方案

Have a look at the second part of this answer: https://stackoverflow.com/a/15885302/1218605

You can create a property on your subclass into which you will set the canvas from the main workspace.

@implemenation C4WorkSpace

-(void)setup {
    CustomSubclass *obj = [CustomSubclass new];
    obj.canvas = self.canvas;
}

@end
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top