(NO.00004)iOS实现打砖块游戏(十三):伸缩自如,我是如意金箍棒(下)!
来源:互联网 发布:seo能自学吗 编辑:程序博客网 时间:2024/04/30 02:10
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处.
如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! hopy ;)
准备缩短反弹棒素材
和上一篇类似,我们如法炮制一张缩短后反弹棒的素材.
打开SpriteBuilder,新建StickShorter.ccb文件,按下图绘制其sprite帧和物理对象:
注意,在Ai中缩小和放大原来反弹棒的图片时,只要沿X轴一个方向放大即可,否则在Y轴方向也会变大,这就不是我们想要的了.
创建缩短道具星
我们用红色的星星表示缩短道具,所以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];}
大家可以和变长的对应代码对比下,基本都是一样的.
下面编译运行游戏,效果如下:
大家可以在变短和变长中添加更多的特效,脑洞打开吧,童鞋们 ;)
0 0
- (NO.00004)iOS实现打砖块游戏(十三):伸缩自如,我是如意金箍棒(下)!
- (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
- (NO.00004)iOS实现打砖块游戏(十):砖块!更多的砖块!
- (NO.00004)iOS实现打砖块游戏(十六):导弹发射道具的实现(下)
- (NO.00004)iOS实现打砖块游戏(三):游戏主场景和砖块
- (NO.00004)iOS实现打砖块游戏(八):游戏中小球与砖块的碰撞
- (NO.00004)iOS实现打砖块游戏(四):砖块类的实现
- (NO.00004)iOS实现打砖块游戏(二):实现游戏主界面动画
- (NO.00004)iOS实现打砖块游戏(五):游戏场景类
- (NO.00004)iOS实现打砖块游戏(九):游戏中小球与反弹棒的碰撞
- (NO.00004)iOS实现打砖块游戏(七):关卡类的实现
- (NO.00004)iOS实现打砖块游戏(十四):3球道具的实现
- (NO.00004)iOS实现打砖块游戏(十五):导弹发射道具的实现(上)
- (NO.00004)iOS实现打砖块游戏(一):素材的制作
- (NO.00004)iOS实现打砖块游戏(六):反弹棒类
- (NO.00004)iOS实现打砖块游戏(十一):"一闪一闪亮晶晶,我们都是小星星"
- 一个简单的打砖块游戏实现
- 打砖块游戏源码
- spring3.1 profile 配置不同的环境
- [leetcode] 115. Distinct Subsequences 解题报告
- Struts2:访问servlet三大域request/session/application属性
- C++的编译单元、可执行程序、内部连接与外部连接
- NumberPicker简单用法(情感状态为例)
- (NO.00004)iOS实现打砖块游戏(十三):伸缩自如,我是如意金箍棒(下)!
- 1.引用 Microsoft Excel 12.0 object library 和 ActiceX Data Objects 2.8 library.
- ML—SVM高级应用总结
- c++文件操作精简详解
- 【Java并发编程实战】-----线程基本概念
- JavaScript基础篇,Object类型
- HttpClient入门2
- socket系统调用
- 1.9以后Jquery不支持attr啦!