水果忍者划痕效果
来源:互联网 发布:kali windows 双系统 编辑:程序博客网 时间:2024/04/27 20:07
转自:http://blog.csdn.net/u012945598/article/details/17609281
网上找的一个关于水果忍者划痕的,效果还算凑合。其原理就是基于OpenGL绘制直线,由于版本过老,此处笔者修改了一些方法,粘贴后可直接使用
适用于Cocos2d-x 2.2.1
.h文件中需要加入的代码:
void draw();
void drawLine();
virtual void ccTouchesBegan(CCSet *pTouches,CCEvent *pEvent);
virtual void ccTouchesMoved(CCSet *pTouches,CCEvent *pEvent);
virtual void ccTouchesEnded(CCSet *pTouches,CCEvent *pEvent);
std::list<CCPoint> pointList;
.cpp文件中
void HelloWorld::draw()
{
drawLine();
}
void HelloWorld::drawLine()
{
int tickSubCount = 10;
int pointListKeepCount = 500;
for (int i=0; i<tickSubCount ; i++)
{
if (pointList.size() >0)
{
pointList.pop_front();
}
else
{
break;
}
}
while (pointList.size() > pointListKeepCount)
{
pointList.pop_front();
}
float max_lineWidth = 5;
float min_lineWidth = 1;
int alpha_min = 10;
int alpha_max = 200;
int R = arc4random()%255;
int G = arc4random()%255;
int B = arc4random()%255;
int pointListCount = pointList.size();
std::list <CCPoint>::iterator it =pointList.begin();
float pointIndex = 0;
for(;it!=pointList.end();it++)
{
int distanceToMiddle = fabs(pointIndex-pointListCount/2);
float percent = 1.0-(float)distanceToMiddle/(float)(pointListCount/2.0);
float lintWidth = min_lineWidth + max_lineWidth*percent;
int alpha = alpha_min +alpha_max*percent;
ccc4(R,G,B,alpha );
ccPointSize(lintWidth);
ccDrawPoint( *it );
pointIndex++;
}
}
void HelloWorld::ccTouchesBegan(CCSet *pTouches,CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)*it;
CCPoint beginPoint = touch->getLocationInView();
beginPoint = CCDirector::sharedDirector()->convertToGL(beginPoint);
pointList.push_back(beginPoint);
}
void HelloWorld::ccTouchesMoved(CCSet *pTouches,CCEvent *pEvent)
{
CCSetIterator it = pTouches->begin();
CCTouch* touch = (CCTouch*)*it;
CCPoint nextPoint = touch->getLocationInView( );
nextPoint = CCDirector::sharedDirector()->convertToGL(nextPoint);
CCPoint preMovePoint = touch->getPreviousLocationInView();
preMovePoint = CCDirector::sharedDirector()->convertToGL(preMovePoint);
float distance = ccpDistance(nextPoint, preMovePoint);
if (distance > 1)
{
int d = (int)distance;
for (int i =0; i < d; i++ )
{
float distanceX = nextPoint.x - preMovePoint.x;
float distanceY = nextPoint.y - preMovePoint.y;
float percent = i / distance;
CCPoint newPoint;
newPoint.x = preMovePoint.x + (distanceX * percent);
newPoint.y = preMovePoint.y + (distanceY * percent);
pointList.push_back(newPoint);
}
}
}
void HelloWorld::ccTouchesEnded(CCSet *pTouches,CCEvent *pEvent)
{
pointList.clear();
}
- 水果忍者划痕效果
- Cocos2d-x 水果忍者划痕效果
- Cocos2d-x 水果忍者划痕效果
- 游戏效果解密----水果忍者刀划痕效果
- OpenGL: 水果忍者刀锋效果
- [Unity3d]水果忍者-切水果功能
- [Unity3d]水果忍者-切水果功能
- 怎么用PS做出划痕的效果?
- 水果忍者
- 天地会朋友分享的一个水果忍者的画线效果
- 水果忍者高分攻略
- 水果忍者JS版
- 水果忍者(二)
- Phaser实现水果忍者
- PTA 一 水果忍者
- 用haXe+NME实现水果忍者的刀光效果,支持多点触摸,Flash10, Android通用
- 什么水果去火效果最好?
- 水果忍者分数存放位置
- 关于iOS 中得block传值问题献给新手
- Radasm使用简明手册(中文版)
- 第四章的思维导图
- Failure [INSTALL_PARSE_FAILED_MANIFEST_MALFORMED]
- 【Access2007】Access2007的打开方式
- 水果忍者划痕效果
- ios runloop 与多线程
- 块链(字符)串
- Codeforces Round #277 (Div. 2) A (水题)B(水题) C(贪心)
- vimrc添加cscope.out
- 约瑟夫环问题
- jquery ajax 请求、解析返回来的xml数据
- VC中GBK与UTF8字符串的转换
- 数据结构与算法学习之路:优化的冒泡排序