Saturday, 15 February 2014

ios - Foreach Loop with 2 variables -



ios - Foreach Loop with 2 variables -

i have created foreach loop follows

(int = 0; < 30; i++) { nsuserdefaults * defaults = [nsuserdefaults standarduserdefaults]; nscalendar *c = [nscalendar currentcalendar]; nsdate *nowdate = [nsdate date]; nsdate *treedate = [defaults objectforkey:@"tree_1"]; nsdatecomponents *components = [c components:nshourcalendarunit fromdate:treedate todate:nowdate options:0]; nsinteger treeint = components.hour; if(treeint >= 0){ [_tree1 setspriteframe:[ccspriteframe framewithimagenamed:@"treestump.png"]]; } }

what trying accomplish have tree_1 , _tree1 increment loop. not sure how add together i onto variable in 2 locations. within @"" , setspriteframe method

for example, i == 3 string @"tree_4" , variable _tree4.

i think need following, using cocos2d here can access sprites added in parent have.

[nsstring stringwithformat:@"tree_%i", + 1]; if(treeint >= 0){ ccsprite *sprite = (ccsprite*)[self getchildbytag:i+1]; [sprite setspriteframe:[ccspriteframe framewithimagenamed:@"treestump.png"]]; }

just need set tags sprite while creating same sequence.

ios foreach

No comments:

Post a Comment