(NO.00004)iOS实现打砖块游戏(十三):伸缩自如,我是如意金箍棒(下)!
2015-11-30 10:13
633 查看
大熊猫猪·侯佩原创或翻译作品.欢迎转载,转载请注明出处.
如果觉得写的不好请告诉我,如果觉得不错请多多支持点赞.谢谢! 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]; }
大家可以和变长的对应代码对比下,基本都是一样的.
下面编译运行游戏,效果如下:
大家可以在变短和变长中添加更多的特效,脑洞打开吧,童鞋们 ;)
相关文章推荐
- 如何让iOS 保持界面流畅
- (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
- (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
- (NO.00004)iOS实现打砖块游戏(十二):伸缩自如,我是如意金箍棒(上)!
- 首发iOS9开发教程
- iOS之 kamailio-4.3.4sip服务器搭建-mac
- ios编码规范
- IOS-32-AFNetworking中与安全相关的AFSecurityPolicy模块详解
- iOS~block的使用
- iOS开发-工具:OS X下如何获得屏幕中颜色的RGB值
- iOS开发中Quartz2D绘图路径的使用以及条纹效果的实现
- IOS 应用 判断是否第一次启动
- (NO.00004)iOS实现打砖块游戏(十一):"一闪一闪亮晶晶,我们都是小星星"
- (NO.00004)iOS实现打砖块游戏(十一):"一闪一闪亮晶晶,我们都是小星星"
- (NO.00004)iOS实现打砖块游戏(十一):"一闪一闪亮晶晶,我们都是小星星"
- iOS书籍
- 关于iOS中简单实现调用系统相机及相册功能
- iOS小技巧14-Openfire管理控制台无法登陆的问
- iOS开发 JSON解析 NSJSONSerialization
- iOS如何定制键盘