Syncing sprite animations in cocos2d -
every , add pulsating sprites scene so:
ccspritebatchnode *batch = (ccspritebatchnode*) [scene getchildbytag: foo1];  sprite = [ccsprite spritewithbatchnode:batch rect:cgrectmake(0, 0, 128, 128)]; sprite.position = foo2 cctintto *a = [cctintto actionwithduration: .5 red:128 green: 128 blue: 128]; cctintto *b = [cctintto actionwithduration: .5 red:255 green: 255 blue: 255];  [sprite runaction:[ccrepeatforever actionwithaction:                    [ccsequence actionone:  two: b]]];  [batch addchild: sprite]; i have sprites pulsating in sync, how go this?
hmmm ... not easy. way i'd see of doing schedule 'flasherramp' so:
in .h
nsmutablearray *flashers; in .m, init method
flashers = [[nsmutablearray array] retain]; // choose own arc flavor, if retain                                              // dont forget release in dealloc  [self schedule:@selector(flasherramp) interval:1.0f]; in .m, create sprite
foo2.visible=no; [flashers addobject foo2]; finally
-(void) flasherramp {     (ccsprite *flasher in flashers) {         cctintto *a = [cctintto actionwithduration: .5 red:128 green: 128 blue: 128];         cctintto *b = [cctintto actionwithduration: .5 red:255 green: 255 blue: 255];          [flasher runaction:[ccrepeatforever actionwithaction:                [ccsequence actionone:  two: b]]];         flasher.visible=yes;     }     [flashers removeallobjects]; } ps. there drift eventually, depending on how long goes on for.
pps. usability perspective, may not idea if there causality between appearance of flashing sprites , 'asynchronous' gaming event may induce delay of 1 second between triggering event , actual appearance of flasher.
ob cit. : coded memory, not tested, should close.
Comments
Post a Comment