0

CoCos2dの開発を始めましたが、ノードスペースとアクションに問題があると思います。これは私のコードであり、コードの実行時にエラーは発生していないようですが、何も移動していません。コメントをいただければ幸いです。

    +(id) create {
    return [[self alloc] init];}

    -(id) init {
        if ((self = [super init]))
        {
        CGSize scSize = [[CCDirector sharedDirector] winSize];

    self.position = ccp(0,scSize.height);;


    touchArea = [CCSprite spriteWithFile:@"touchArea.png"]; 
    [touchArea setAnchorPoint:ccp(0, 0.5)];
    [self addChild:touchArea];


    obj_1 = [CCSprite spriteWithFile:@"obj1.png"];
    obj_2 = [CCSprite spriteWithFile:@"obj2.png"];
    obj_3 = [CCSprite spriteWithFile:@"obj3.png"];

    obj_tab = [NSMutableArray arrayWithObjects:obj_1, obj_2, obj_3, nil];


        for (int i=0; i < obj_tab.count; i++)
        {
            CCSprite *obj = [obj_tab objectAtIndex:i];
            float offSetPos = ((float)(i+1)) / (obj_tab.count +1);
            CGPoint pos = ccp(scSize.width*offSetPos, 0);
            obj.position = pos;
            [obj setAnchorPoint:ccp(0.5, -0.25)];
            [touchArea addChild:obj];
        }

    velocidad = 3;
    destino = ccp(0,-100);
    //[self scheduleUpdate];
    [self moveIt] // <-- Edited to call another method
 }   
    return self;

}

-(void) moveit{
    CCMoveTo *moverAction = [CCMoveTo actionWithDuration:5 position:ccp(0,0)];
    CCCallFunc *onEndAction = [CCCallFunc actionWithTarget:self selector:@selector(onEndMove:)];
    CCSequence *moveSequence = [CCSequence actions: moverAction, onEndAction, nil];
    [touchArea runAction:moveSequence];
{

-(void) update:(ccTime)delta {

}

-(void)onEndMove:(id)sender{
    NSLog(@"OnEndMove fired");
}

-(void) onEnter{
    [[CCTouchDispatcher sharedDispatcher] addTargetedDelegate:self priority:-1 swallowsTouches:YES];
}

-(void) onExit {
    [[CCTouchDispatcher sharedDispatcher] removeDelegate:self];
}


-(BOOL) ccTouchBegan:(UITouch *)touch withEvent:(UIEvent *)event{

    CGRect boundingBox = touchArea.boundingBox;
    boundingBox.origin = CGPointZero;

    BOOL isTouchHandled = CGRectContainsPoint(boundingBox, [touchArea convertTouchToNodeSpace: touch]);

    //NSLog(@"touchLocation y = %f", touchLocation.y);
    //NSLog(@"touchArea y = %f", touchArea.position.y);

    if (isTouchHandled){
        NSLog(@"Touch Handled");
    }

    return isTouchHandled;

}
@end
4

2 に答える 2

0

どのくらいの頻度-(void) update:(ccTime)deltaで呼び出されていますか?(おそらくあなたのscheduleUpdateメソッドで開始されます。)おそらく[touchArea runAction:moveSequence];、1秒間に数回それを呼び出しており、それらのCCMoveToのトンをキューに入れています。

おそらく、runAction:sを完全にそこから移動するか、少なくともupdate:メソッドにロジックを追加して、別のを開始する必要があるかどうかを確認するtouchArea必要がありますrunAction:

于 2012-06-18T22:59:46.227 に答える
0

上に示したコードのクラスである「self」はCCNodeから派生していると思います。'self'が実行されていることを確認してください。これは、CCNodeの子孫である必要があり、実行中のノードに追加されたときに実行されます。これは、CCNodeのonEnter(バージョン1.0.1から取得)で発生することです。

-(void) onEnter
{
    [children_ makeObjectsPerformSelector:@selector(onEnter)];  
    [self resumeSchedulerAndActions];

    isRunning_ = YES;
}

これは、ノードに対してスケジューラーとアクションが有効になっている場所です。呼び出されない場合、アクションは実行されません。

moveItコードをonEnterメソッドに移動できます。このメソッドは、オブジェクトが実行されるときに呼び出されます。

-(void) onEnter{
    CCLOG(@"%@<onEnter> : invoked",self.class);
    [self moveIt];
    [super onEnter];   
}
于 2012-06-19T13:50:33.240 に答える