[Cocos2d-x]代码段记录
2013-12-07 02:24
246 查看
一些零碎的代码,便于以后查找
1.添加动画
2.替换CCSprite的纹理
3.Touch事件处理
1.添加动画
//添加动画帧 CCAnimation* animation = CCAnimation::create(); for(int i = 1; i< 6;i++) { char imgsName[100] = {0}; sprinft(imgsName,”img_%d.png”,i); animation->addSpriteFrameWithFileName(imgsName); } animation->setDelayPerUnit(1.0f); animation->setRestoreOriginalFrame(true); animation->setLoop(-1); //使用动画帧创建动画 CCAnimate* animate = CCAnimate::create(animation); this->runAction(animate);
2.替换CCSprite的纹理
setTexture(CCTexture2D)
3.Touch事件处理
bool SoundSprite::ccTouchBegan(cocos2d::CCTouch *touch, cocos2d::CCEvent *event) { CCPoint touchPoint = convertToNodeSpace(touch->getLocation()); CCRect rect = CCRect(getPositionX() - getContentSize().width * getAnchorPoint().x, getPositionY() - getContentSize().height * getAnchorPoint().y, getContentSize().width, getContentSize().height); rect.origin = CCPointZero; bool isTouchedIn = rect.containsPoint(touchPoint); if (isTouchedIn) { CCLog("SoundSprite::ccTouchBegan"); m_PlaySound = !m_PlaySound; this->initWithFile(m_PlaySound?I_FARM_SOUND_ON:I_FARM_SOUND_OFF); return true; } return false; }
相关文章推荐
- cocos2d-x+VS+lua项目(android)(简要记录)
- cocos2d-x问题记录
- cocos2d-x问题记录
- cocos2d-x-2.1在Mac OS下编译输出到android手机 - 过程记录
- 游戏开发记录120811:cocos2d-x引擎学习---目录结构及主要类
- cocos2d-x3.2 在Windows下打包Android平台APK(转载,只为记录)
- cocos2d-x ios工程引擎升级记录
- 记录cocos2d-html5与cocosd-x jsb中遇到的坑
- cocos2d-x v2.2 IOS工程支持64-bit 遇坑记录
- 记录之——cocos2d-x v3.0 发布说明
- cocos2d-x+VS+lua项目(android)(简要记录)
- cocos2d-x问题记录
- Cocos2d-js 开发记录:Loading载入界面自定义
- 记录一个xp下运行cocos2d-x tests例子报错的解决过程
- 【Cocos2d-x】问题解决记录--解决extensions库编译报错问题
- Ubuntu 13.04 配置Cocos2d-x记录
- 【Cocos2d-x】VS2012开发2dx无法解析的外部符号解决记录(第二篇)
- Cocos2d-js 开发记录:图片数据资源等的异步加载
- cocos2d-x项目过程记录(ios和android设备的适配)
- Cocos2d-x开发---关于安卓打包所遇到的错误记录