【Cocos2d-x 粒子系统】火球用手指飞起来
程序:
创建球
sp1 = CCSprite::create("ball.png"); sp1->setPosition(ccp(10, visibleSize.height/2)); this->addChild(sp1); setTouchEnabled(true);
让球飞起来吧,创建个简单粒子,点哪飞到哪
void HelloWorld::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { CCSize winSize = CCDirector::sharedDirector()->getVisibleSize(); if (sp1) { //获取点击位置转GL CCPoint location = pTouch->getLocationInView(); CCPoint pos = CCDirector::sharedDirector()->convertToGL(location); CCLOG("ccTouchEnded...x:%f y:%f", pos.x, pos.y); //创建粒子系统,设置參数 CCParticleSystem *cps = CCParticleSun::create(); cps->retain(); cps->setPosition(ccp(0,5));//位置 cps->setLife(0.06f);//每个粒子的生命周期 sp1->addChild(cps);//添加到图层向导 CCActionInterval *by = CCMoveTo::create(1, ccp(pos.x, pos.y)); //移动 sp1->runAction(by); } }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步