我正在使用C4应用程序,并创建了C4Shape的子类。我无法从子类中访问画布,但我不确定如何检查它,或者如何从另一个对象访问它。
这是我到目前为止的代码:
#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
答案 0 :(得分:1)
看一下这个答案的第二部分:https://stackoverflow.com/a/15885302/1218605
您可以在子类上创建一个属性,您将从主工作区设置画布。
@implemenation C4WorkSpace
-(void)setup {
CustomSubclass *obj = [CustomSubclass new];
obj.canvas = self.canvas;
}
@end