cocos2d iphone - On CCBitmapFontAtlas effect (Display on by one) -
cocos2d iphone - On CCBitmapFontAtlas effect (Display on by one) -
i'm trying create effect using ccbitmapfontatlas, here want:
the string "abcdefg" beingness dispayed 1 one, each 1 won't displayed until 1 before displayed.
and here tried:
-(id) init
{ if( (self=[super init] )) {
label = [ccbitmapfontatlas bitmapfontatlaswithstring:@"abc" fntfile:@"bitmapfonttest.fnt"]; [self addchild:label]; cgsize s = [[ccdirector shareddirector] winsize]; label.position = ccp(s.width/2, s.height/2); label.anchorpoint = ccp(0.5f, 0.5f); label.visible = no; //hide first [[cctouchdispatcher shareddispatcher] addtargeteddelegate:self priority:0 swallowstouches:yes]; } homecoming self;
}
-(bool) cctouchbegan:(uitouch *)touch withevent:(uievent *)event
{ ccsprite achar = (ccsprite) [label getchildbytag:0]; ccsprite bchar = (ccsprite) [label getchildbytag:1]; ccsprite cchar = (ccsprite) [label getchildbytag:2];
id fade_in = [ccfadein actionwithduration:3]; label.visible = yes; [achar runaction:fade_in]; [bchar runaction:fade_in]; [cchar runaction:fade_in]; homecoming yes;
}
the effect "abc" fade in 1 time touched screen, tried utilize callfuncnd phone call next string fade in while current string displayed. seems create things complex.
is there easier way effect done? suggestion appreciate.
i sense going in right direction one. have each letter separate sprite , store them in array , run them each 1 one.
the phone call function can started by:
[self displaynextsprite:spritearray nextindex:0];
and function is:
// warning, assumes not passing empty array, may want set in check -(void)displaynextsprite:(nsmutablearray*)spritearray nextindex:(nsuinteger)nextindex { ccsprite *nextsprite = [spritearray objectatindex:nextindex]; id action1 = [ccfadein actionwithduration:3]; // or = [ccpropertyaction actionwithduration:3 key:@"opacity" from:0 to:255]; // lastly letter if(nextindex == ([spritearray count] - 1)) { [nextsprite runaction:action1]; } else // go on next letter { id callfunc = [cccallfunc actionwithtarget:self selector:@selector(displaynextsprite:spritearray nextindex:nextindex+1)]; id sequence = [ccsequence actionone:action1 two:callfunc]; [nextsprite runaction:sequence]; } }
cocos2d-iphone
Comments
Post a Comment