所以我来自一些处理背景(虽然不多),我习惯于使用在应用程序运行时反复运行的绘制循环。
我似乎在 xcode 和 C4 中找不到类似的东西。有什么人可以建议的吗?
我基本上在做的只是使用 C4 向量作为自定义类中的属性创建一个弹跳球应用程序
这是我的自定义类头/实现文件:
@interface splitSquare : C4Shape
@property C4Vector *accel;
@property C4Vector *velocity;
@property C4Vector *location;
-(id)initWithPoint:(CGPoint)point;
@end
-(id)initWithPoint:(CGPoint)point{
self = [super init];
if (self){
CGRect frame = CGRectMake(0, 0, 50, 50);
[self ellipse:frame];
self.lineWidth = 0.0f;
self.fillColor = [UIColor colorWithRed:[C4Math randomInt:100]/100.0f
green:[C4Math randomInt:100]/100.0f
blue:0.5f
alpha:1.0f];
_location = [C4Vector vectorWithX:point.x Y:point.y Z:0.0f];
self.origin = _location.CGPoint;
_accel = [C4Vector vectorWithX:0.04f Y:0.05f Z:0.0f];
_velocity = [C4Vector vectorWithX:0.004f Y:0.0005f Z:0.0f];
C4Log(@"The current value of velocity x is %f and y is %f", _velocity.x, _velocity.y);
}
我正在做一些非常简单的事情(将加速度添加到速度和速度到位置,然后将位置分配给形状原点)。在主 C4WorkSpace 中,我有以下代码:
@interface C4WorkSpace()
-(void)updateVectors;
@end
@implementation C4WorkSpace
{
splitSquare *testShape;
C4Timer *timer;
}
-(void)setup {
testShape = [[splitSquare alloc] initWithPoint:point2];
[self.canvas addShape:testShape];
testShape.animationDuration = 0.25f;
timer = [C4Timer automaticTimerWithInterval:0.25f target:self method:@"updateVectors" repeats:YES];
}
-(void)updateVectors{
//accel add to vel, vel added to location
[testShape.velocity add:testShape.accel];
[testShape.location add:testShape.velocity];
testShape.origin = testShape.location.CGPoint;
testShape.fillColor = [UIColor colorWithRed:[C4Math randomInt:100]/100.0f
green:[C4Math randomInt:100]/100.0f
blue:0.5f
alpha:1.0f];
}
@end
所以这就是我现在正在做的事情,一个 C4 计时器被调用,但我觉得必须有一种更优雅的方式来做到这一点。现在动画很跳跃,虽然它没有抛出错误,但它似乎无法正常工作(每次我运行 iOS 模拟器时,它都会运行一秒钟,然后跳回 xcode 并向我显示当前线程)。
任何/所有建议都会很棒,谢谢!