【发布时间】:2010-04-14 11:02:05
【问题描述】:
我的游戏中有一段文字是用 cocos2d 编写的。当我们触摸并上下移动文本时,文本会上下移动。文字在动。但是在触摸结束时它没有回到原始位置。所以,我写了 cade 以获取文本以获取原始位置。但问题是我现在无法阅读全文。我需要的是滚动效果。如何在 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;
}
【问题讨论】:
标签: cocoa-touch iphone-sdk-3.0 cocos2d-iphone