小编Mor*_*ion的帖子

iPhone SDK audioSession问题

在我的应用程序中,我同时录制和播放音频.该应用程序几乎完成.但是有一件事让我烦恼.当音频会话设置为PlayAndRecord时,与SoloAmbient类别的相同声音相比,声音变得安静.有没有什么方法可以使用PlayAndRecord让声音更响亮?

iphone audio session objective-c

6
推荐指数
1
解决办法
4353
查看次数

根据用户触摸位置旋转精灵图像?

我开始学习游戏开发。作为一名初学者,我创建了一个演示游戏,其中一门大炮向敌人发射子弹(从不同方向朝大炮射来)。现在,我在用户触摸屏幕或敌人的任何地方都坚持大炮精灵图像旋转。我如何做到这一点,我的初始代码如下,

void HelloWorld:: ccTouchesBegan(CCSet *touches, CCEvent * event)
{
    CCSize winSize = CCDirector::sharedDirector()->getWinSize(); 
    CCTouch* touch = (CCTouch*)( touches->anyObject() );
    CCPoint location = touch->locationInView(touch->view());
    location = CCDirector::sharedDirector()->convertToGL(location);

    //Rotate cannon direction toward touch point
    CCPoint diffPoint = ccpSub(_cannonImage->getPosition(), location);
    float angleRadians = atanf((float)diffPoint.y/(float)diffPoint.x);
    float angleOffset = CC_DEGREES_TO_RADIANS(180);

    if(diffPoint.x < 0){
        angleRadians += angleOffset;
    }else{
        angleRadians -= angleOffset;
    }

    CCLog("angle to be rotate = %f", angleRadians);

    _cannonImage->runAction(CCRotateBy::actionWithDuration(0.1, angleRadians));

}
Run Code Online (Sandbox Code Playgroud)

代码是用 cocos2d-x 编写的。我也接受用普通 cocos2d 编写的人的回答。

谢谢我饿了

iphone cocos2d-iphone ios cocos2d-x

5
推荐指数
2
解决办法
5880
查看次数

CCLayer周围的边界

我正在使用Cocos2d来拖动精灵,并尝试在选择精灵时添加边框.我可以让我的白色背景显示,但我的边界证明特别困难.我有这个代码:

if(self.selectedSprite)
    self.selectedSprite = nil;

CCLayerColor *selectedLayer = [[CCLayerColor alloc] init];
//    CCSprite *backgroundSprite = [CCSprite spriteWithFile:@"white_1x1.gif" rect:CGRectMake(2,2,self.boundingBox.size.width-4,self.boundingBox.size.height-4)];
CCSprite *backgroundSprite = [CCSprite spriteWithFile:@"white_1x1.gif" rect:CGRectMake(0,0,self.boundingBox.size.width,self.boundingBox.size.height)];
[backgroundSprite setContentSize:CGSizeMake(self.contentSize.width-4, self.contentSize.height-4)];
backgroundSprite.anchorPoint = ccp(0,0);

CCRenderTexture* rt = [CCRenderTexture renderTextureWithWidth:backgroundSprite.texture.contentSize.width + 2  height:backgroundSprite.texture.contentSize.height+2];

[backgroundSprite setFlipY:YES];
[backgroundSprite setColor:ccc3(0,0,0)];
ccBlendFunc originalBlendFunc = [backgroundSprite blendFunc];
[backgroundSprite setBlendFunc:(ccBlendFunc) { GL_SRC_ALPHA, GL_ONE }];

CGPoint bottomLeft = ccp(backgroundSprite.texture.contentSize.width * backgroundSprite.anchorPoint.x + 1, backgroundSprite.texture.contentSize.height * backgroundSprite.anchorPoint.y + 1);
CGPoint position = ccpSub([backgroundSprite position], ccp(-backgroundSprite.contentSize.width / 2.0f, -backgroundSprite.contentSize.height / 2.0f));

[rt begin];

for …
Run Code Online (Sandbox Code Playgroud)

iphone cocos2d-iphone cclayer ios

1
推荐指数
1
解决办法
3148
查看次数

标签 统计

iphone ×3

cocos2d-iphone ×2

ios ×2

audio ×1

cclayer ×1

cocos2d-x ×1

objective-c ×1

session ×1