CCBlade (Slash effect like in Fruit Ninja) has been ported to Cocos2d-x (tested in Marmalade platform)

Hello everyone,
I was looking for slash effect when the user swipe his finger on screen that will look like Fruit Ninja (arrow shape getting thinner).
CCMoitionStreak wasn’t very satisfying - it was too sharp in the corners, it didn’t has an arrow shape and didn’t get thinner.
So I found CCBlade here:

I ported it to C++ and test it in Marmalade platform, the results are great!
here you can see it in action in my game, Rolly Poly:
[[http://www.youtube.com/watch?v=5jHBgKSzij0]]
The code, of course, is attached. the usage is very simple - just add TouchTrailLayer::node() to your scene as a child.
Big thanks to Ngo Duc Hiep who wrote this wonderful class in the first place.

P.S - there might be a small memory leak, I didn’t find it yet, if anyone will find something, please post it here.

(ignore .h and .cpp attached files, the updated version is attached - ccblade.zip)


streak1.png (1.4 KB)


CCBlade.cpp.zip (2.3 KB)


CCBlade.h.zip (1.2 KB)


TouchTrailLayer.cpp.zip (1.4 KB)


TouchTrailLayer.h.zip (1.0 KB)


ccblade.zip (5.9 KB)

Hi Leo…. Looks cool… Thanks for the work!

BTW, is your game Rolly Poly made with Cocos2dx and Marmalade?

Yes

Oh, perhaps it’s the first cocos2d-x game using Marmalade platform.

I guess so, I started working on it when cocos2d-airplay extension wasn’t official and was only a post of a forum discussions.
Btw - my game is already available for download:
http://www.roymam.com/rollypoly/getfullversion.php

So are you planning on releasing to Android as well?

For what it’s worth, I’ve installed the lite version of Rolly Poly on my iPhone 4 and it works great…. and the slash effect looks good too!

The slash effect on the version you installed is the older one and uses CCMoitionStreak, the new one (with CCBlade) hasn’t been published yet.
I’m planning to release it on Android too later, My Marmalade license currently doesn’t allow it.

I also tried to import it. However, it looks there are some defects on the code.
From original CCBlade example, it continues to be added to layer every time we want to draw a blade. It will not be destroyed or remove from parent.
Therefore, after you run the game with 900+ blades, the system crashes.

Note: You cannot delete the blade manually after it finish rendering. If you do it, the system crash instantly.

you right, the blade is never deleted unless you delete the parent.
I added “getParent()->removeChild(this,true)” after the blade is faded, I used schedule to run it because when running inside the draw() function the system crash.
try it now. flie (ccblade.zip) is attached.

you right, the blade is never deleted unless you delete the parent.
I added “getParent()->removeChild(this,true)” after the blade is faded, I used schedule to run it because when running inside the draw() function the system crash.
try it now. file (ccblade.zip) is attached.

I’ve added a link to this topic in sticky FAQ.

Hi,

I can compile example successfully. However, it can show Cocos2d startup image but no further action. There is no error message.
2012-02-15 19:16:59.736 Example[2668:207] cocos2d: compiled with Affine Matrix transformation in CCNode : YES
2012-02-15 19:16:59.736 Example[2668:207] cocos2d: compiled with Profiling Support: NO
2012-02-15 19:16:59.744 Example[2668:207] Retina Display Not supported
2012-02-15 19:16:59.797 Example[2668:207] cocos2d: Frame interval: 1
2012-02-15 19:16:59.800 Example[2668:207] cocos2d: surface size: 320x480

I am using Base SDK iphone device 4.0 and iPhone OS Deployment Target iPhone OS 3.2.
Would you please give me some advice to fix it?
Thanks.

p0o0q

thank you so much … it’s very useful for me

I fixed the problem. Thanks.

This class does not work in cocos2d-x 2.0 version.

it shouldnt be that hard to upgrade

just here.

https://github.com/smilingpoplar/CCBlade

I have some trouble with CCBlade.cpp

CCBlade* pRet = new CCBlade(filePath, stroke, pointLimit);

Allocating an object of abstract class type ‘CCBlade’

Can U help me pls ?:slight_smile: THX!

use my version of CCBlade

https://github.com/jandujar/CCBlade.git

And don’t forget that you need to create a TouchTrailLayer, not a CCBlade.

TouchTrailLayer *layer = TouchTrailLayer::create();
addChild(layer);

Can anybody port this to version 3? :slight_smile: