2

だから私は、アプリの実行中に何度も実行される描画ループでの作業に慣れている、処理のバックグラウンド (それほど多くはありません) から来ています。

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 シミュレーターを実行するたびに、1 秒間実行されてから xcode に戻り、現在のスレッドが表示されます)。

あらゆる/すべての提案は素晴らしいものになるでしょう!

4

1 に答える 1