cocos2dx 以子弹飞行为例解说拖尾效果类CCMotionStreak
在游戏开发中,有时会须要在某个游戏对象上的运动轨迹上实现渐隐效果。比方子弹的运动轨迹,假设不借助引擎的帮助,这样的效果则须要通过大量的图片来实现。而Cocos2D-x的拖动渐隐效果类CCMotionStreak就帮助我们实现这个效果。以下是子弹飞行火焰拖尾的效果实现。。
- #include "HelloWorldScene.h"
- #include "SimpleAudioEngine.h"
- using namespace cocos2d;
- using namespace CocosDenshion;
- CCScene* HelloWorld::scene()
- {
- CCScene *scene = CCScene::create();
- HelloWorld *layer = HelloWorld::create();
- scene->addChild(layer);
- return scene;
- }
- bool HelloWorld::init()
- {
- if ( !CCLayer::init() )
- {
- return false;
- }
- size = CCDirector::sharedDirector()->getWinSize();
- CCLayerColor* background = CCLayerColor::create(ccc4(255, 200, 255, 255), size.width, size.height);
- this->addChild(background);
- //存储子弹节点
- bulltArr = CCArray::create();
- CC_SAFE_RETAIN(bulltArr);
- //存储 CCMotionStreak
- streakArr = CCArray::create();
- CC_SAFE_RETAIN(streakArr);
- scheduleUpdate();
- return true;
- }
- void HelloWorld::update(float delta)
- {
- for (int i = 0; i < bulltArr->count(); i++) {
- CCSprite* bullt = (CCSprite*)bulltArr->objectAtIndex(i);
- bullt->setPositionY(bullt->getPositionY()+2);
- CCMotionStreak* streak = (CCMotionStreak*)streakArr->objectAtIndex(i);
- //每次调用setPosition函数又一次设置对象位置时,“影子”将被创建而且慢慢渐隐 注:对于CCMotionStreak对象不可用getPosition()等方法。。
- streak->setPosition(bullt->getPosition());
- }
- for (int i = 0; i < bulltArr->count(); i++) {
- CCSprite* bullt = (CCSprite*)bulltArr->objectAtIndex(i);
- //删除超出屏幕节点
- if (bullt->getPositionY() >= size.height+bullt->getContentSize().height) {
- this->removeChild(bullt);
- bulltArr->removeObject(bullt);
- CCSprite* streak = (CCSprite*)streakArr->objectAtIndex(i);
- this->removeChild(streak);
- streakArr->removeObject(streak);
- break;
- }
- }
- }
- //拖尾效果类CCMotionStreak
- //创建 子弹节点 和 CCMotionStreak对象
- void HelloWorld::createBullt(CCPoint startPoint)
- {
- CCSprite* bullt = CCSprite::create("bullet3.png");
- bullt->setPosition(startPoint);
- this->addChild(bullt,2);
- bulltArr->addObject(bullt);
- //第一个參数是间隐的时间,第二个參数是间隐片断的大小,第三个參数是贴图的宽高,第四个參数是颜色值RGB,第五个參数是贴图的路径或者贴图对象
- CCMotionStreak* streak = CCMotionStreak::create(0.8, 10, 10, ccRED, "bullet3.png");
- streak->setPosition(startPoint);
- this->addChild(streak,1);
- streakArr->addObject(streak);
- }
- bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
- {
- createBullt(pTouch->getLocation());
- return true;
- }
- void HelloWorld::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent){}
- void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent){}
- void HelloWorld::onEnter()
- {
- CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this, 0, false);
- CCLayer::onEnter();
- }
- void HelloWorld::onExit()
- {
- CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
- CCLayer::onExit();
- }
- HelloWorld::~HelloWorld()
- {
- CC_SAFE_RELEASE(bulltArr);
- CC_SAFE_RELEASE(streakArr);
- }
cocos2dx 以子弹飞行为例解说拖尾效果类CCMotionStreak的更多相关文章
- cocos2dx 子弹飞作为一个例子来解释解酒效果类CCMotionStreak
感谢点评与关注,欢迎转载与分享. 勤奋努力,持之以恒! 在游戏开发中,有时会须要在某个游戏对象上的运动轨迹上实现渐隐效果.比方子弹的运动轨迹,假设不借助引擎的帮助.这样的效果则须要通过大量的图片来实现 ...
- cocos2d-x 2.0 拖尾效果分析
转自:http://game.dapps.net/gamedev/game-engine/7281.html 在Cocos2d-x中,拖尾效果有一个专门的类CCMotionStreak来实现.下面我们 ...
- [Cocos2d-x For WP8]MotionStreak拖尾效果
拖尾效果是指在在游戏中,一个精灵在运动的过程中会留下一个短暂的轨迹效果,在游戏里面如打斗的特效往往会需要用到这种效果来给运动的增加绚丽的效果.那么在Cocos2D-x里面我们可以使用一种内置的拖动渐隐 ...
- 【转】Cocos2d-x 2.0 拖尾效果深入分析
Cocos2d-x 2.0 拖尾效果深入分析 另:本章所用Cocos2d-x版本为: cocos2d-2.0-x-2.0.2@ Aug 30 2012 http://cn.cocos2d-x.org/ ...
- [Unity3d]向量的过度方法以及拖尾效果
Vector3.RotateTowards() 用法 public static function RotateTowards(current: Vector3, target: Vector3, m ...
- 浅谈canvas中的拖尾效果
引言 很早就想了解以下 canvas 中的拖尾效果(如彗星,烟花等效果)是怎么实现的,但是一直没有深入了解,正巧在 codepen 上看到一个 demo,代码简单,效果炫酷,故有此文. 什么黑科技 在 ...
- Cocos Creator 的实现拖尾效果
在游戏中,有时会需要在某个游戏对象上加上移动后的轨迹若隐若现的效果.使得游戏的效果较好,比如游戏大招,刀光,法术,流星划痕之类. Cocos Creator提供了一种内置的拖尾渐隐效果的实现方法:组件 ...
- Unity3D-飞机拖尾效果
1.插件准备 unity3d官网,Assert Store搜索Cartoon_airplane 插件 2.拖尾效果实现 飞机显示 拖尾组件设计 在airplane_02下 右键 Effects-Tra ...
- Unity 武器拖尾效果
Pocket RPG Weapon Trails 武器拖尾效果 Asset Store地址:https://www.assetstore.unity3d.com/en/#!/content/2458 ...
随机推荐
- 程序员老鸟写sql语句的经验之谈
做管理系统的,无论是bs结构的还是cs结构的,都不可避免的涉及到数据库表结构的设计,sql语句的编写等.因此在开发系统的时候,表结构设计是否合理,sql语句是否标准,写出的sql性能是否优化往往会成为 ...
- 从 IT 的角度思考 BIM(一):面向对象
还记得那个笑话吗:要把大象放进冰箱,总共分几步?这不仅仅是一个笑话,还是一个值得我们好好分析的笑话. 如果要放进冰箱的是一个苹果,那么也就不可笑了,但换成大象,就引起了我们的兴趣和注意,为什么? 我们 ...
- .net 反射访问私有变量和私有方法
以下为本次实践代码: using System; using System.Collections.Generic; using System.ComponentModel; using System ...
- Nth Digit | leetcode
Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, ... Note: n i ...
- caller和callee的区别
①.caller caller返回一个函数的引用,这个函数调用了当前的函数. 使用这个属性要注意: 1 这个属性只有当函数在执行时才有用 2 如果在javascript程序中,函数是由顶层调用的,则返 ...
- Investigation of Different Nets and Layers
Investigation of Different Nets and Layers Overview of AlexNet (MIT Places | Flickr Finetuned | Oxfo ...
- 中断服务程序(Interrupt Service Routines,ISR)注意事项
转自ISR之不能做什么 中断是嵌入式系统中重要组成部分,很多编译器开发商都让标准c支持中断,并引入关键字_interrupt.但是: 1.ISR不能有返回值: 2.ISR不能传递参数: 3.ISR应该 ...
- 怎样在Win7 64位旗舰版安装Python+Eclipse开发环境
原地址:http://www.cnblogs.com/balian/archive/2011/06/19/2084632.html 自从上周抛弃了WinXP转而安装了Win7,64位后,尝试安装Pyt ...
- 运行 Docker 容器时的安全风险:别丢了你的套接字
我们都遇到过这种情况:你只是想尝试一段命令行,但安装进程却如同抵押贷款申请那般繁琐.如果不是强制要求完成这么多步骤,你的开发环境会被永远不会再使用的库弄乱.自然, Docker 来了以后,你惊异地发现 ...
- iOS各种系统通知Name
当了一次搬运工,原地址:http://blog.csdn.net/db905517804/article/details/50569949 用法: - (void) viewWillAppear:(B ...
