cocos 屏幕抖动,3.10可以用
来源:互联网 发布:类似trackid的软件 编辑:程序博客网 时间:2024/05/16 17:42
cocos 屏幕抖动,3.10可以用 ,x->runAction(CCShake::create(1.0f, 5));
#ifndef __SHAKE_H__ #define __SHAKE_H__ #include "cocos2d.h" USING_NS_CC;class CCShake : public cocos2d::CCActionInterval{public:CCShake();// Create the action with a time and a strength (same in x and y) static CCShake *create(float d, float strength);// Create the action with a time and strengths (different in x and y) static CCShake *createWithStrength(float d, float strength_x, float strength_y);bool initWithDuration(float d, float strength_x, float strength_y);protected:void startWithTarget(cocos2d::CCNode *pTarget);void update(float time);void stop(void);CCPoint m_StartPosition;// Strength of the action float m_strength_x, m_strength_y;};#endif //__SHAKE_H__
#include "CShake.h"
#include "cocos2d.h"
USING_NS_CC;
// not really useful, but I like clean default constructors
CCShake::CCShake() : m_strength_x(0), m_strength_y(0)
{
}
CCShake *CCShake::create(float d, float strength)
{
// call other construction method with twice the same strength
return createWithStrength(d, strength, strength);
}
CCShake *CCShake::createWithStrength(float duration, float strength_x, float strength_y)
{
CCShake *pRet = new CCShake();
if (pRet && pRet->initWithDuration(duration, strength_x, strength_y))
{
pRet->autorelease();
}
else
{
CC_SAFE_DELETE(pRet);
}
return pRet;
}
bool CCShake::initWithDuration(float duration, float strength_x, float strength_y)
{
if (CCActionInterval::initWithDuration(duration))
{
m_strength_x = strength_x;
m_strength_y = strength_y;
return true;
}
return false;
}
// Helper function. I included it here so that you can compile the whole file
// it returns a random value between min and max included
static float fgRangeRand(float min, float max)
{
float rnd = ((float)rand() / (float)RAND_MAX);
return rnd * (max - min) + min;
}
void CCShake::update(float dt)
{
float randx = fgRangeRand(-m_strength_x, m_strength_x) * dt;
float randy = fgRangeRand(-m_strength_y, m_strength_y) * dt;
// move the target to a shaked position
//m_pTarget->setPosition(ccpAdd(m_StartPosition, ccp(randx, randy)));
_target->setPosition(ccpAdd(m_StartPosition, ccp(randx, randy)));
}
void CCShake::startWithTarget(CCNode *pTarget)
{
CCActionInterval::startWithTarget(pTarget);
// save the initial position
m_StartPosition = pTarget->getPosition();
}
void CCShake::stop(void)
{
// Action is done, reset clip position
this->getTarget()->setPosition(m_StartPosition);
CCActionInterval::stop();
}
- cocos 屏幕抖动,3.10可以用
- 屏幕抖动脚本
- mfc屏幕抖动问题
- cocos2dx屏幕抖动效果
- 用as3实现组件或屏幕的抖动效果
- 用as3实现组件或屏幕的抖动效果
- cocos 屏幕适配
- 防止调用中的屏幕抖动
- 显示器屏幕总是抖动原因
- 显示器屏幕抖动原因汇总
- Cocos Builder-----屏幕适配
- cocos-js,屏幕适配
- cocos-笔记-判断方向-屏幕
- 基于屏幕像素抖动的PCF
- 基于屏幕像素抖动的PCF
- [Unity3D] 战场电视屏幕抖动扭曲Shader
- 页面跳转时屏幕出现抖动现象
- cocos 3.10 web 接入小熊平台 ios不能屏幕适配
- CVTE面试
- 小型直播系统系列-乐聊TV的开发(三)
- 字符串库函数
- c++primer plus阅读笔记(五)
- SQL 语句关键词笔记二
- cocos 屏幕抖动,3.10可以用
- elasticsearch 学习历程
- 根据两个位置的经纬度,来计算两地的距离(单位为KM)
- 电商中用户余额/积分以及库存的设计
- python 格式化字符串 format() 函数
- Spring 配置拦截器 HandlerInterceptor
- 从学习SaaS引申学习的一些关键词概念
- NIO服务端
- 验证用户名和密码是否为空的两种方式