Introduction to C # Learning log day9--------------cocos2d-x 3.0 particle effects

Source: Internet
Author: User
Tags addchild

Cocos2d is a useful game engine that can be used in Windows Phone, but it's not so good that its code can only be written in C + +.

Because of our WP application I am responsible for the implementation of particle effects, so here I introduce a variety of particle effects.

The cocos2d comes with 10 particle effects. It can be said that the general effect of the cocos2d can be used with the particle effect of the implementation. Even if we can't, we can achieve the effect we want by adjusting some properties of its own particle effect.

Here we first put out 10 kinds of particle effect implementation code

Particlerain *snow = Particlerain::create ();//the effect of rainSnow->setposition (Point ( -, -)); Snow->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Black.png"), Rect (0,0,Ten,Ten));  This-AddChild (Snow); Particleexplosion*exp = Particleexplosion::create ();//explosion effectExp->setposition (Point ( -, -)); Exp->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (exp); Particlefire*fire = Particlefire::create ();//Flame EffectFire->setposition (Point ( $, -)); Kindle->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (fire); Particlesun*sun = Particlesun::create ();//The Sun effect. The gravity of the flame effect is set to 0.Sun->setposition (Point ( -, -)); Sun->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (Sun); Particlegalaxy*ga = Particlegalaxy::create ();//Galaxy effect,Ga->setposition (Point ( -, -)); GA->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (GA); Particlesmoke*SM = Particlesmoke::create ();//the effect of smoke, slower than the flameSm->setposition (Point ( -, -)); SM->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-addChild (SM); Particlemeteor*PM = Particlemeteor::create ();//Popular EffectsPm->setposition (Point ( -, $)); PM->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (PM); Particleflower*PB = Particleflower::create ();//the effect of the flower, the personal feeling of special disorderPb->setposition (Point ( $, $)); PB->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (PB); Particlespiral*ps = Particlespiral::create ();//Spiral ShapePs->setposition (Point ( -, $)); PS->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This-AddChild (PS); Particlefireworks*PF = Particlefireworks::create ();//Fireworks EffectPf->setposition (Point ( -, $)); PF->settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,Ten,Ten));  This->addchild (PF);

The simple results can be clearly seen. are ugly.

But this is because the use of pictures is not selected and has not been adjusted.

Here are a few key attributes that can be tweaked to make the particle effect cool.

Particlemeteor *pm = Particlemeteor::create ();
Settexturewithrect (Director::getinstance ()->gettexturecache ()->addimage ("Yellow.png"), Rect (0,0,5,5));//the picture referenced by the particle and the size of the rectpm->setposition (Point (x, y));//the location that appearspm->setgravity (Point (-2,0));//Gravity settingPm->setstartsize (8.0f);//the size of the particle at the beginningPm->settotalparticles (550);//set number of particlesPm->setduration (0.5);//particle duration, in seconds

When clicked, the effect lasts for 0.5 seconds, then disappears, and the touch continues to appear for 0.5 seconds.

Introduction to C # Learning log day9--------------cocos2d-x 3.0 particle effects

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.