내 게임에 cocos2d로 작성된 텍스트가 있습니다. 텍스트를 터치하거나 위아래로 움직이는 동안 텍스트가 위아래로 움직입니다. 텍스트가 움직입니다. 하지만 터치가 끝나면 원래 위치로 돌아 가지 않습니다. 그래서, 나는 원래 위치를 얻기 위해 텍스트를 끝낸 접촉에 대해 캐드를 썼다. 그러나 문제는 내가 지금 전체 텍스트를 읽을 수 없다는 것입니다. 스크롤 효과가 필요한 것입니다. 어떻게 cocos2d에서 만들 수 있습니까?cocos2d에서 레이어를 스크롤하는 방법을 추가 하시겠습니까?
-(void) ccTouchMoved:(UITouch *)touch withEvent:(UIEvent *)event
{
CGPoint touchLocation = [touch locationInView: [touch view]];
CGPoint prevLocation = [touch previousLocationInView: [touch view]];
touchLocation = [[CCDirector sharedDirector] convertToGL: touchLocation];
prevLocation = [[CCDirector sharedDirector] convertToGL: prevLocation];
CGPoint diff = ccpSub(touchLocation,prevLocation);
CCNode *node = [self getChildByTag:kTagNode];
CGPoint currentPos = [node position];
[node setPosition: ccpAdd(currentPos, diff)];
}
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
{
CGSize windowSize = [[CCDirector sharedDirector] winSize];
CCNode *node = [self getChildByTag:kTagNode];
[node setPosition: ccp(text1.contentSize.width/2,text1.contentSize.height/2 - windowSize.height)];
}
-(id) init
{
if((self = [super init]))
{
CGSize windowSize = [[CCDirector sharedDirector] winSize];
self.isTouchEnabled = YES;
NSString *dataPath = @"/Users/sridhar/Srikanth/DrawGameSrikanth/ResourcestextData.txt";
NSString *dataString = [[NSString alloc] initWithContentsOfFile:dataPath];
CCLabel *text1 = [CCLabel labelWithString: dataString dimensions: CGSizeMake(300, 600) alignment: UITextAlignmentLeft fontName:@"American Typewriter" fontSize:24];
text1.position = ccp(text1.contentSize.width/2 ,text1.contentSize.height/2 - windowSize.height);
text1.color = ccc3(0, 0, 0);
CCNode *node = text1;
CCParallaxNode *voidNode = [CCParallaxNode node];
[voidNode addChild:node z:2 parallaxRatio:ccp(0.0f,1.0f) positionOffset:ccp(text1.contentSize.width/2,text1.contentSize.height/2 - windowSize.height)];
[self addChild: voidNode z:2 tag:kTagNode];
}
return self;
}