简体   繁体   English

如何在cocos2d-iphone中的精灵之后建立静态路径?

[英]How can I make a static path after sprite in cocos2d-iphone?

There is a sprite (paper plane) that "flows in the air". 有一个精灵(纸飞机)“在空气中流动”。 I'd like make a path that follows after (look below) but it should be static(not moving together with paper plane, just appearing after it). 我想创建一条遵循该路径的路径(如下所示),但它应该是静态的(不随纸平面一起移动,仅出现在其后)。 I supposed just to make a long sprite with the path, but in this way it would move too, and it's not so nice. 我本来只是想用路径做一个长的精灵,但是这样它也会移动,而且不是很好。 Also, it should dissapear at the same time as sprite. 而且,它应该与精灵同时消失。 (cocos2d-iphone 3.0) (cocos2d-iphone 3.0)

How can I implement it? 我该如何实施?

在此处输入图片说明

What you could do is schedule an update method that runs every second (or faster) that checks the plane's center and adds a small line underneath the plane's center position. 您可以做的是安排一个更新方法,该方法每秒钟(或更快)运行一次,该方法检查飞机的中心并在飞机的中心位置下方添加一条细线。

You also store the new sprite in an array and when the plane disappears from the screen you loop through the array and remove each sprite from the screen. 您还将新的精灵存储在数组中,当平面从屏幕上消失时,您将遍历数组并从屏幕上删除每个精灵。

Hope that helps 希望能有所帮助

You can give this kind of effect by using CCMotionStreak 您可以使用CCMotionStreak产生这种效果

CCTexture2D *mytexture=CCTextureCache::sharedTextureCache()->addImage("plane_path.png");
CCMotionStreak *motion_plane =CCMotionStreak::create(5,1,20,ccc3(255,0,0),mytexture);
motion_plane->setPosition(ccp(30,30));
motion_plane->setZOrder(5);
this->addChild(motion_plane);

Now u only need to set position of motion streak according to plane and it will show path with fading effect. 现在您只需要根据平面设置运动条纹的位置,它将显示具有衰落效果的路径。 it will look great . 看起来很棒。 hope you understand. 希望你能理解。

I use Cocos2DX 2.2.X Version. 我使用的是Cocos2DX 2.2.X版本。 I used CCMotionStreak for this kind of effect. 我使用CCMotionStreak来达到这种效果。 I think that version also has it whatever you are using. 我认为该版本也具有它,无论您使用什么。 Just have a look on that class you will get to know how to use it. 只需看一下该类,您就会知道如何使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM