1

我试过这段代码它不起作用,我希望按钮在单击时播放声音。

-(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;

怎么了?

4

3 回答 3

0

A)设置断点——任何程序员的必备知识。

B) CCMenuItemImage 选择器不带参数。删除冒号@selector(startButtonSound)并将方法更改为:

-(void)starButtonsound
{
    [[SimpleAudioEngine sharedEngine] playEffect:@"fire_truck_1.wav"];
}
于 2013-02-22T15:13:42.473 回答
0

有人报告说这是一个解决方案:关闭并再次打开声音(不是开玩笑)

[SimpleAudioEngine sharedEngine].muted = YES;
[SimpleAudioEngine sharedEngine].muted = NO;
于 2013-02-22T15:25:43.110 回答
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"];
}
于 2013-02-22T15:31:59.760 回答