2014-11-21 86 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"]; 
} 

希望這會有所幫助。