I have a text in my game which is written in cocos2d. The text moves up and down while we touch and move it up or down. The text is moving. But it is not getting to original position while touches ended. So, I wrote cade for touches ended for text to get original position. But problem is i could not read the entire text now. What I need is scrolling effect. How can I make it in 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;
}