2013-02-22 78 views
1

我試過這個代碼,它沒有工作,我想按鈕播放聲音時,它被點擊。聲音按鈕不起作用? COCOS2D

-(void)starButtonsound:(id)sender 
{ 
    [[SimpleAudioEngine sharedEngine] playEffect:@"fire_truck_1.wav"]; 
} 

在初始化

starMenuItemsound = [CCMenuItemImage 
        itemWithNormalImage:@"play.png" selectedImage:@"play.png" 
        target:self selector:@selector(starButtonsound:)]; 
starMenuItemsound.position = ccp(525, 500); 
[self addChild:starMenuItemsound z: 4]; 
starMenuItemsound.scale = 0.75; 

的哪些錯誤?

+0

需要更多信息。究竟是什麼做錯了? – Almo 2013-02-22 15:10:27

+0

可以顯示控制檯中的日誌嗎? – 2013-02-22 15:24:14

+0

看起來像cocosDenshion標籤上缺少SO – 2013-02-22 15:26:26

回答

0

在初始化

{ 
    // Using SpriteSheet ? Use spriteWithSpriteFrameName in place of spriteWithFile 
     CCSprite *spriteNormal = [CCSprite spriteWithFile:@"play.png"]; 
     CCSprite *spriteSelected = [CCSprite spriteWithFile:@"play.png"]; 
     ccColor3B color = {128,128,128}; 
     spriteSelected.color = color; 

     starMenuItemsound = [CCMenuItemImage 
         itemWithNormalSprite: spriteNormal selectedImage: spriteSelected 
         target:self selector:@selector(starButtonsound:)]; 
     starMenuItemsound.position = ccp(525, 500); 
     starMenuItemsound.scale = 0.75; 

     CCMenu *menu = [CCMenu menuWithItems: starMenuItemsound, nil]; 
     menu.position = ccp(0.0f,0.0f); 
     [self addChild: menu z:4]; 
    } 

來電功能:

-(void) starButtonsound:(id)sender 
{ 
    [[SimpleAudioEngine sharedEngine] setEffectsVolume:1.0f]; //Do this in init method 
    [[SimpleAudioEngine sharedEngine] playEffect:@"fire_truck_1.wav"]; 
} 
0

A)Set a breakpoint - 任何程序員的基本知識。

B)CCMenuItemImage選擇器不接受參數。從@selector(startButtonSound)取出結腸並改變方法這樣:

-(void)starButtonsound 
{ 
    [[SimpleAudioEngine sharedEngine] playEffect:@"fire_truck_1.wav"]; 
} 
+0

它似乎並不有所作爲.. - (無效)starButtonsound { [SimpleAudioEngine sharedEngine] playEffect:@ 「fire_truck_1.wav」]; } starMenuItemsound = [CCMenuItemImage itemWithNormalImage:@ 「play.png」 selectedImage:@ 「play.png」 目標:自選擇器:@selector(starButtonsound)]; starMenuItemsound.position = ccp(525,500); // CCMenu * starMenusound = [CCMenu menuWithItems:starMenuItem,nil]; [self addChild:starMenuItemsound z:4]; starMenuItemsound.scale = 0.75; 我很困惑.. – user2083920 2013-02-22 15:21:38

0

一些報道,這是一個解決方案:聲音關閉和再次打開(無笑話)

[SimpleAudioEngine sharedEngine].muted = YES; 
[SimpleAudioEngine sharedEngine].muted = NO;