2010-04-14 5 views
0

내 게임에 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; 
} 

답변

1

이렇게하면 cocos2d 레이어에 textView가 만들어지고 데이터가 위아래로 스크롤됩니다. 그러나 이것에 문제가 있습니다.

"Copperplate Gothic Bold"와 같이 textView의 텍스트에 사용자 지정 글꼴을 사용할 수 없습니다. 시스템 글꼴 만 사용할 수 있습니다. 그러나 위의 코드는 모든 글꼴을 사용할 수 있습니다.

-(id)init 
{ 
if((self = [super init])) 
{ 
    self.isTouchEnabled = YES; 
    CGSize windowSize = [[CCDirector sharedDirector] winSize]; 

    description = [[UITextView alloc] initWithFrame:CGRectMake(50,150,200 ,200)]; 
    description.backgroundColor = [UIColor clearColor]; 
    description.text = enemyDescription; //enemyDescription is a string from plist in my code 
    [description setEditable:NO]; 
    description.font = [UIFont fontWithName:@"Arial Unicode MS" size:14.0f]; 

    description.showsHorizontalScrollIndicator = NO; 

    description.alwaysBounceVertical = YES; 

    description.transform = CGAffineTransformMakeRotation(CC_DEGREES_TO_RADIANS(90.0f)); 

    [[[CCDirector sharedDirector]openGLView]addSubview:description]; 
    [description release]; 
} 

다시 제거하기 위해 우리는 다음과 같은 코드 나는이 당신을 도움이되기를 바랍니다

NSArray *subviews = [[[CCDirector sharedDirector]openGLView] subviews]; 
for (id sv in subviews) 
{ 
    [((UIView *)sv) removeFromSuperview]; 
    [sv release]; 
} 

을 사용해야합니다. 제안 사항은 게시 해주십시오.

관련 문제