(NO.00004)iOS實現打磚塊遊戲(十三):伸縮自如,我是如意金箍棒(下)!

來源:互聯網
上載者:User

(NO.00004)iOS實現打磚塊遊戲(十三):伸縮自如,我是如意金箍棒(下)!

 

準備縮短反彈棒素材

和上一篇類似,我們如法炮製一張縮短後反彈棒的素材.

開啟SpriteBuilder,建立StickShorter.ccb檔案,按繪製其sprite幀和物理對象:

vc/y0rK74bHktPMs1eK+zbK7ysfO0sPHz+vSqrXEwcsuPC9wPg0KPGgyIGlkPQ=="建立縮短道具星">建立縮短道具星

我們用紅色的星星表示縮短道具,所以spawStar中是這樣寫的:

case brkColorRed:            star = [Star starWithType:starTypeStickShorter];            break;

在GameScene.m中,在星星與反彈棒碰撞的代碼中,加入如下代碼:

case starTypeStickShorter:            @synchronized(self){                [self scheduleBlock:^(CCTimer *timer){                    [Star doStickShorterWork:self.stickInGameScene];                } delay:0];            }            break;

好了,最後我們回到Star.m中添加doStickShorterWork方法:

+(void)doStickShorterWork:(Stick *)stick{    GameScene *gameScene = [GameScene sharedGameScene];    CCPhysicsNode *physicsWorld = (CCPhysicsNode*)stick.parent;    @synchronized(gameScene){        if ([stick.name isEqualToString:@stickShorter]) {            return;        }        if ([stick.name isEqualToString:@stickLonger]) {            Stick *stickNormal = [Stick stickNormal];            stickNormal.position = stick.position;            [stick removeFromParent];            //[physicsWorld removeChild:stick cleanup:YES];            [physicsWorld addChild:stickNormal];            gameScene.stickInGameScene = stickNormal;            return;        }    }    CGPoint position = stick.position;    __block Stick *stickShorter;    @synchronized(gameScene){        stickShorter = [Stick stickShorter];        [stick removeFromParent];        //[physicsWorld removeChild:stick cleanup:YES];        stickShorter.position = position;        [physicsWorld addChild:stickShorter];        stickShorter.visible = NO;        gameScene.stickInGameScene = stickShorter;        CCSprite *stickNode = (CCSprite*)[CCBReader load:@Elements/StickNode];        stickNode.position = stickShorter.position;        [gameScene addChild:stickNode z:50];        CCActionScaleTo *shorterAction = [CCActionScaleTo actionWithDuration:0.4f scaleX:0.5f scaleY:1.0f];        CCActionCallBlock *blk = [CCActionCallBlock actionWithBlock:^{            [stickNode removeFromParent];            stickShorter.visible = YES;        }];        CCActionSequence *seq = [CCActionSequence actions:shorterAction,blk,nil];        [stickNode runAction:seq];    }    [stickShorter scheduleBlock:^(CCTimer *timer){        @synchronized(gameScene){            Stick *stickNormal = [Stick stickNormal];            stickNormal.position = stickShorter.position;            [stickShorter removeFromParent];            [physicsWorld addChild:stickNormal];            gameScene.stickInGameScene = stickNormal;        }    } delay:10];}

大家可以和變長的對應代碼對比下,基本都是一樣的.

下面編譯運行遊戲,效果如下:

大家可以在變短和變長中添加更多的特效,腦洞開啟吧,童鞋們 ;)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.