2014-11-21 3 views
0

내 메인 메뉴에는 화면 하단에 사운드 로고가 있습니다. 나는 spriteNoedeWithImageNamed를 가지고 있었지만 꼭 필요하면 텍스처를 바꿀 때 텍스쳐를 사용하지 않고 어떻게해야 하는지를 알 수 없다. 내 문제는 내가 텍스처로 넣었고 이제는 전혀로드되지 않는다는 것입니다. 나는 이것이 단순한 문제라는 것을 알고 있지만, 나는 하루 종일 이것에 대해 일 해왔고 나는 해결책을 생각할 수 없다.spriteNodeWithTexture가 로딩되지 않습니다.

{ 
BOOL myBool; 
//SKSpriteNode *soundLogo; 
SKTexture *soundOn; 
SKTexture *soundOff; 
} 

-(void) addSoundLogo:(CGSize)size { 
SKSpriteNode *soundLogo = [SKSpriteNode spriteNodeWithTexture:soundOn]; 
//resize sprite 
soundLogo.size = CGSizeMake(soundLogo.size.width/2.25, soundLogo.size.height/2.25); 
//position sprite 
CGPoint myPoint = CGPointMake(65, 25); 
soundLogo.position = myPoint; 
//name sound logo 
soundLogo.name = @"soundLogo"; 
//add action 

[self addChild:soundLogo]; 


} 

답변

0

이 방법을 장면에 추가하십시오. 보기 컨트롤러 대신 사용하는 경우 locationInNode : locationInView :

touchesBegan 대신 다른 방법으로 추가해야하는 경우 : 이제 텍스처를 사용하여이를 수행하는 방법을 알 수 있습니다. 경고를 없애기 위해 포인터를 초기화하기 전에 반환 값에 캐스트를 넣었는지 확인하십시오.

-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 
    //_bgLayer is the node that you put your SKSpriteNodes on. 
    SKSpriteNode * node = (SKSpriteNode*)[_bgLayer nodeAtPoint:[[touches anyObject] locationInNode:_bgLayer]]; 
    //wallTile is the name of the texture you want it to be changed to. 
    node.texture = [SKTexture textureWithImageNamed:@"wallTile"]; 
} 

이 정보가 도움이되기를 바랍니다.

관련 문제