ios - CAEmitterLayer not Shown -


i'm adding uiview storyboard view controller , creating uiview class display particle effect. change uiview's class name of custom class created. code i'm using in uiview class not display particle effect expected. code follows:

- (void)drawrect:(cgrect)rect {     // drawing code          cgrect viewbounds = rect;      fireworksemitter.emitterposition = cgpointmake(viewbounds.size.width/2.0, viewbounds.size.height);     fireworksemitter.emittersize    = cgsizemake(viewbounds.size.width/2.0, 0.0);     fireworksemitter.emittermode    = kcaemitterlayeroutline;     fireworksemitter.emittershape   = kcaemitterlayerline;     fireworksemitter.rendermode     = kcaemitterlayeradditive;     fireworksemitter.seed = (arc4random()%100)+1;      // create rocket     caemittercell* rocket = [caemittercell emittercell];      rocket.birthrate        = 1.0;     rocket.emissionrange    = 0.25 * m_pi;  // variation in angle     rocket.velocity         = 380;     rocket.velocityrange    = 100;     rocket.yacceleration    = 75;     rocket.lifetime         = 1.02; // cannot set birthrate < 1.0 burst      rocket.contents         = (id) [[uiimage imagenamed:@"dazring"] cgimage];     rocket.scale            = 0.2;     rocket.color            = [[uicolor redcolor] cgcolor];     rocket.greenrange       = 1.0;      // different colors     rocket.redrange         = 1.0;     rocket.bluerange        = 1.0;     rocket.spinrange        = m_pi;     // slow spin        // burst object cannot seen, spawn sparks     // change color here, since sparks inherit value     caemittercell* burst = [caemittercell emittercell];      burst.birthrate         = 1.0;      // @ end of travel     burst.velocity          = 0;     burst.scale             = 2.5;     burst.redspeed          =-1.5;      // shifting     burst.bluespeed         =+1.5;      // shifting     burst.greenspeed        =+1.0;      // shifting     burst.lifetime          = 0.35;      // , finally, sparks      caemittercell* spark = [caemittercell emittercell];      spark.birthrate         = 400;     spark.velocity          = 125;     spark.emissionrange     = 2* m_pi;  // 360 deg     spark.yacceleration     = 75;       // gravity     spark.lifetime          = 3;      spark.contents          = (id) [[uiimage imagenamed:@"dazstaroutline"] cgimage];     spark.scalespeed        =-0.2;     spark.greenspeed        =-0.1;     spark.redspeed          = 0.4;     spark.bluespeed         =-0.1;     spark.alphaspeed        =-0.25;     spark.spin              = 2* m_pi;     spark.spinrange         = 2* m_pi;      // putting     fireworksemitter.emittercells   = [nsarray arraywithobject:rocket];     rocket.emittercells             = [nsarray arraywithobject:burst];     burst.emittercells              = [nsarray arraywithobject:spark];     [self.layer addsublayer:fireworksemitter];      [self setneedsdisplay]; } 

1) remove of code drawrect, , put uiview subclass init method, or, since you're using storyboard, put awakefromnib:

- (void)awakefromnib {     [super awakefromnib];      cgrect viewbounds = rect;      fireworksemitter = (caemitterlayer*)self.layer;     fireworksemitter.emitterposition = cgpointmake(viewbounds.size.width/2.0, viewbounds.size.height);     fireworksemitter.emittersize    = cgsizemake(viewbounds.size.width/2.0, 0.0);     fireworksemitter.emittermode    = kcaemitterlayeroutline;     fireworksemitter.emittershape   = kcaemitterlayerline;     fireworksemitter.rendermode     = kcaemitterlayeradditive;     fireworksemitter.seed = (arc4random()%100)+1;      // create rocket     caemittercell* rocket = [caemittercell emittercell];      rocket.birthrate        = 1.0;     rocket.emissionrange    = 0.25 * m_pi;  // variation in angle     rocket.velocity         = 380;     rocket.velocityrange    = 100;     rocket.yacceleration    = 75;     rocket.lifetime         = 1.02; // cannot set birthrate < 1.0 burst      rocket.contents         = (id) [[uiimage imagenamed:@"dazring"] cgimage];     rocket.scale            = 0.2;     rocket.color            = [[uicolor redcolor] cgcolor];     rocket.greenrange       = 1.0;      // different colors     rocket.redrange         = 1.0;     rocket.bluerange        = 1.0;     rocket.spinrange        = m_pi;     // slow spin      caemittercell* burst = [caemittercell emittercell];     burst.birthrate         = 1.0;      // @ end of travel     burst.velocity          = 0;     burst.scale             = 2.5;     burst.redspeed          =-1.5;      // shifting     burst.bluespeed         =+1.5;      // shifting     burst.greenspeed        =+1.0;      // shifting     burst.lifetime          = 0.35;      caemittercell* spark = [caemittercell emittercell];     spark.birthrate         = 400;     spark.velocity          = 125;     spark.emissionrange     = 2* m_pi;  // 360 deg     spark.yacceleration     = 75;       // gravity     spark.lifetime          = 3;      spark.contents          = (id) [[uiimage imagenamed:@"dazstaroutline"] cgimage];     spark.scalespeed        =-0.2;     spark.greenspeed        =-0.1;     spark.redspeed          = 0.4;     spark.bluespeed         =-0.1;     spark.alphaspeed        =-0.25;     spark.spin              = 2* m_pi;     spark.spinrange         = 2* m_pi;      fireworksemitter.emittercells   = [nsarray arraywithobject:rocket];     rocket.emittercells             = [nsarray arraywithobject:burst];     burst.emittercells              = [nsarray arraywithobject:spark]; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -