ios - Using CCScrollView in Cocos2d V3 -
i'm wondering if can help me this. want add together 4 ccscrollviews, scroll horizontally, on ccnode. ccnode, positioned , held on device in portrait mode, fill entire screen normalized contentsize set cover entire screen.
so in essence scroll views pile on top of each other 4th beingness @ bottom of screen , 1st beingness @ top. now, have managed add 4 ccscrollviews 1 responds touches. others flat unmovable. it's though lastly ccscrollview added node overlaying other 3 , thing responding touch requests. 4 ccscrollviews have delegate property set self.
i'm coming @ cocos2d fair bit of uikit experience. so, i'm trying apply uiscrollview mode of thinking of this. having had google , coming little, i'm wondering if can help. i've been considering winding uiscrollview cocos2d.
i guess main issues here two-fold. one, have issue touch response. two, have issue paging aspect , command of content-size. via trial , error, i'm sort of getting along if perhaps write bit of best-practive guide ccscrollview implementation, 1 not set contentsize of ccnode or ccspriteframe that's added larger contentview not fill entire width of screen.
thanks in advance.
#import "cctoolkit.h" #import "gameship.h" typedef enum shippart { shipparthead, shippartbody, shippartwings, shippartboosters } shippart; @implementation gameship -(instancetype)init { if (self = [super init]) { [self addbackground]; [self addscrollto:shipparthead forqtyofparts:3]; [self addscrollto:shippartbody forqtyofparts:4]; [self addscrollto:shippartwings forqtyofparts:3]; [self addscrollto:shippartboosters forqtyofparts:3]; } homecoming self; } -(void)addbackground { ccsprite *bg = [ccsprite spritewithimagenamed:kgamemainbackground]; bg.positiontype = ccpositiontypenormalized; bg.position = ccp(0.5f,0.5f); [self addchild:bg]; } -(void)addscrollto:(shippart)shippart forqtyofparts:(int)partqty { nsstring *imagefilenamesegment; switch (shippart) { case shipparthead: imagefilenamesegment = @"head"; break; case shippartbody: imagefilenamesegment = @"body"; break; case shippartwings: imagefilenamesegment = @"wings"; break; case shippartboosters: imagefilenamesegment = @"boosters"; break; default: break; } ccnode *scrollviewcontents = [ccnode node]; scrollviewcontents.contentsizetype = ccsizetypenormalized; scrollviewcontents.contentsize = cgsizemake(partqty * 0.65, 0.25f); nslog(@"scrollview,height %f", scrollviewcontents.boundingbox.size.height); (int = 1; <= partqty; i++) { nsstring *imagefilename = [nsstring stringwithformat:@"%@%d.png", imagefilenamesegment, i]; ccsprite *shippartsprite = [ccsprite spritewithimagenamed:imagefilename]; shippartsprite.positiontype = ccpositiontypenormalized; shippartsprite.position = ccp((i + 0.5f) / partqty, 0.5f); [scrollviewcontents addchild:shippartsprite]; } ccscrollview *scrollview = [[ccscrollview alloc] initwithcontentnode:scrollviewcontents]; scrollview.pagingenabled = yes; scrollview.horizontalscrollenabled = yes; scrollview.verticalscrollenabled = no; scrollview.color = [cccolor redcolor]; scrollview.contentsize = cgsizemake(0.5f, 0.25f); scrollview.positiontype = ccpositiontypenormalized; scrollview.position = ccp(-1.0f, ((shippart * 0.25f) -0.1f)); scrollview.delegate = self; //scrollview.description = [nsstring stringwithformat:@"%d", shippart]; [self addchild:scrollview]; //[scrollview sethorizontalpage:1]; }
ios objective-c uiscrollview cocos2d-iphone cocos2d-swift
No comments:
Post a Comment