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

希望这会有所帮助。