[一位菜鸟的COCOS-2D编程之路]打飞机中机种敌机和战机损毁时的爆炸效果
1.第一步,添加爆炸动画
//添加玩家飞机飞行动画
id _playerFlyAction; id _playerBlowupAnimation; //战机爆炸动画
id _enemyBlowupAnimation;//敌机爆炸动画
BOOL _isEnemyCollodable; //敌机是否可碰撞
BOOL _isPlayerCollodable;//玩家飞机是否可碰撞
2.制作精灵表单
3.初始化爆炸量
//初始化爆炸效果的量
_playerBlowupAnimation = [self getAnimationByName:@"plane_bao_" delay:0.08 animNum:5];
[_playerBlowupAnimation retain];
_enemyBlowupAnimation = [self getAnimationByName:@"plane2_bao_" delay:0.08 animNum:5];
[_enemyBlowupAnimation retain];
_isEnemyCollodable = YES;
_isPlayerCollodable = YES;
4.添加获取动画帧的图片 的方法
#pragma mark 飞机飞行和爆炸动画
- (CCAnimation *)getAnimationByName:(NSString *)animName delay:(float)delay animNum:(int)num
{
NSMutableArray *animFrames = [NSMutableArray arrayWithCapacity:num]; for (int i=1; i<= num; ++i) {
NSString *frameName = [NSString stringWithFormat:@"%@%d.png",animName,i]; CCSpriteFrame *frame = [[CCSpriteFrameCache sharedSpriteFrameCache] spriteFrameByName:frameName]; [animFrames addObject:frame];
}
CCAnimation *animation = [CCAnimation animationWithSpriteFrames:animFrames delay:delay];
return animation; }
5.修改碰撞
-(void) collisionDetection:(ccTime)dt{
CCSprite *enemy;
// CGRect bulletRect = [self rectOfSprite:_bulletSprite];
CCARRAY_FOREACH(_enemySprites, enemy)
{
if (enemy.visible && _isEnemyCollodable ) {
_isEnemyCollodable = NO;
//1.bullet & enemy collision det ection
// CGRect enemyRect = [self rectOfSprite:enemy];
if (_bulletSprite.visible && CGRectIntersectsRect(enemy.boundingBox, _bulletSprite.boundingBox)) {
//使用CCspawn 动作组合
id ac1 = [CCScaleTo actionWithDuration:1.0 scale:1.2];
id ac2 = [CCRotateBy actionWithDuration:1.0 angle:720];
id ac3 = [CCFadeOut actionWithDuration:1.0];
id ac4 = [CCHide action];
id blowup = [CCAnimate actionWithAnimation:_enemyBlowupAnimation ];
id block = ^(){
_isEnemyCollodable = YES;
};
id ac5 = [CCSequence actions:ac3,ac4,[CCCallBlock actionWithBlock:block], nil];
id action = [CCSpawn actions:ac1,ac2,ac5,blowup, nil];
[enemy stopAllActions];
[enemy runAction:action];
enemy.visible = NO;
_bulletSprite.visible = NO;
_totalScore += 100;
if (_totalScore >= 1000) {
[_gameEndLabel setString:@"游戏胜利!"];
_gameEndLabel.visible = YES;
id scaleTo = [CCScaleTo actionWithDuration:1.0 scale:1.2f];
[_gameEndLabel runAction:scaleTo];
[self unscheduleUpdate];
[self performSelector:@selector(onRestartGame) withObject:nil afterDelay:2.0f];
}
[_bulletSprite stopAllActions];
[enemy stopAllActions];
CCLOG(@"collision bullet");
break;
}
//2.enemy & player collision detection
CCSprite *playerSprite = [self getPlayerSprite];
// CGRect playRect = [self rectOfSprite:playerSprite];
if (playerSprite.visible && _isPlayerCollodable &&
playerSprite.numberOfRunningActions == 0
&& CGRectIntersectsRect(enemy.boundingBox, playerSprite.boundingBox)) {
enemy.visible = NO;
_isPlayerCollodable = NO;
_totalLives -= 1;
if (_totalLives <= 0) {
[_gameEndLabel setString:@"游戏失败!"];
_gameEndLabel.visible = YES;
id scaleTo = [CCScaleTo actionWithDuration:1.0 scale:1.2f];
[_gameEndLabel runAction:scaleTo];
[self unscheduleUpdate];
[self performSelector:@selector(onRestartGame) withObject:nil afterDelay:3.0f];
}
id blink = [CCBlink actionWithDuration:2.0 blinks:4];
id blowup = [CCAnimate actionWithAnimation:_playerBlowupAnimation];
id action = [CCSequence actions:blowup,blink,[CCCallBlock actionWithBlock:^(){
_isPlayerCollodable = YES;[playerSprite stopAllActions];
[playerSprite runAction:_playerFlyAction];
playerSprite.opacity = 255;
playerSprite.visible = YES;}], nil];
[playerSprite stopAllActions];
[playerSprite runAction:action];
CCLOG(@"collision player");
break;
}
}
}
}
[一位菜鸟的COCOS-2D编程之路]打飞机中机种敌机和战机损毁时的爆炸效果的更多相关文章
- 赠书:HTML5 Canvas 2d 编程必读的两本经典
赠书:HTML5 Canvas 2d 编程必读的两本经典 这两年多一直在和HTML5 Canvas 打交道,也带领团队开发了世界首款基于HTML5 Canvas 的演示文档工具---AxeSlide( ...
- 初次踏上GUI编程之路(有点意思,详细介绍了菜鸟的学习之路)
初次踏上GUI编程之路 —— 我的Qt学习方法及对Qt认识的不断转变 -> 开始接触GUI与开始接触Qt: 话说,我第一次看见“Qt”这一个名词,好像是在CSDN网站的主页上吧,因为CSDN好像 ...
- Cocos 2d TestCPP 学习
Cocos 2d testcpp包含了大量的demo, 对于新手学习cocos引擎具有非常大的帮助.因为接下来的开发项目有可能会用到该引擎,所以希望可以利用自己的业余时间提前熟悉起来.该篇文章会记录自 ...
- Quartz 2D编程指南(1) - 概览
Quartz 2D编程指南是论坛会员德鲁伊翻译的国外的Quartz 2D一系列学习资料,供大家参考 Quartz 2D是一个二维图形绘制引擎,支持iOS环境和Mac OS X环境.我们可以使用Quar ...
- [C#] 走进异步编程的世界 - 在 GUI 中执行异步操作
走进异步编程的世界 - 在 GUI 中执行异步操作 [博主]反骨仔 [原文地址]http://www.cnblogs.com/liqingwen/p/5877042.html 序 这是继<开始接 ...
- java编程思想第四版中net.mindview.util包下载,及源码简单导入使用
在java编程思想第四版中需要使用net.mindview.util包,大家可以直接到http://www.mindviewinc.com/TIJ4/CodeInstructions.html 去下载 ...
- C#编程实现Excel文档中搜索文本
有了在Word文档中编程实现搜索文本的经验,在Excel中实现这个功能也并非难事. 打开Excel的VBA帮助,查看Excel的对象模型,很容易找到完成这个功能需要的几个集合和对象:Applicati ...
- VS编程,编辑WPF过程中,点击设计器中界面某一控件,在XAML中高亮突出显示相应的控件代码的设置方法。
原文:VS编程,编辑WPF过程中,点击设计器中界面某一控件,在XAML中高亮突出显示相应的控件代码的设置方法. 版权声明:我不生产代码,我只是代码的搬运工. https://blog.csdn.net ...
- 杂谈---LZ的编程之路以及十点建议
LZ本人是09年毕业的,在某二流本科院校学的非计算机专业,在兴趣的驱使之下,最终毅然决然的走上了编程这一条“不归路”. 说起LZ的经历虽不算是跌宕起伏,但也真正算是人生无常. 当初09年7月回到家里, ...
随机推荐
- 哈希值识别工具hash-identifier
Hash Identifier可以用来识别各种类型的哈希值.在kali上使用方法很简单 (1)搜索hash-identifier (2)在HASH后面输入要识别的hash内容 (3)识别成功 wind ...
- 页面滚动动态加载数据,页面下拉自动加载内容 jquery
<!DOCTYPE=html> <html> <head> < script src="js/jquery.js" type=" ...
- poj 3083 Children of the Candy Corn(DFS+BFS)
做了1天,总是各种错误,很无语 最后还是参考大神的方法 题目:http://poj.org/problem?id=3083 题意:从s到e找分别按照左侧优先和右侧优先的最短路径,和实际的最短路径 DF ...
- UVa 1641 ASCII Area
题意: 就是用一个字符矩阵代表一个闭合的阴影部分,然后求阴影部分的面积. 分析: 一个'/'和'\'字符都代表半个小方块的面积. 关键就是判断'.'是否属于阴影部分,这才是本题的关键. 从第一列开始, ...
- 各种好用的工具之一 ---- PNGGauntlet
1.PNGGauntlet实际上是一个图形前端,压缩图像的过程中使用的是PNGOUT, OptiPNG, 和DeflOpt这三款软件. 软件官网:http://pnggauntlet.com/ 可自行 ...
- 【 随笔 】 D3 难吗?
有不少朋友说学 D3 挺难的.为什么呢?想写一篇文章分析分析. 1. D3 出现的背景 D3.js 是 Github 上的一个开源项目,用于数据可视化.作者是 Mike Bostock,纽约时报的工程 ...
- 自适应的CSS代码片段(常用)
/* Smartphones (portrait and landscape) ----------- */ @media only screen and (min-device-width : 32 ...
- chmod命令
chmod命令用于改变linux系统文件或目录的访问权限.用它控制文件或目录的访问权限.该命令有两种用法.一种是包含字母和操作符表达式的文字设定法:另一种是包含数字的数字设定法. Linux系统中的每 ...
- 29、activity横竖屏切换细节问题
1 import android.app.Activity; import android.content.Intent; import android.os.Bundle; import andro ...
- 【暑假】[实用数据结构]UVAlive 4329 Ping pong
UVAlive 4329 Ping pong 题目: Ping pong Time Limit: 3000MS Memory Limit: Unknown 64bit IO Format: % ...