"BackgroundMoving"代码在iPhone4S中不起作用

NSE*_*ion 10 objective-c cocos2d-iphone

当我在设备上测试我的应用程序(iPhone4)时,我正在制作一个我面临问题的游戏,它的背景不起作用.就像背景图像结束时BLACKISH BACKGROUND COLOR来了.我的背景图片大小为460X2880,图片名称为"mars_sample.jpg"(适用于iPhone4)背景移动的代码为:

-(void)backgroundmoving:(ccTime)dt 
{     
    static float bk_f=0.0f;

    bk_f -=0.9;
    if (bk_f <= -960*3) {bk_f=0;}
    background.position = ccp( 0,bk_f);    
}  
Run Code Online (Sandbox Code Playgroud)

当我将"460X2880"尺寸图像加载为背景图像时,它不会在背景中加载,如果它像大小"460X1192"那样,它会在背景中加载图像,但在屏幕顶部显示BLACKISH BACKGROUND Color.

下面一个CODE用于设置背景图像:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
    background = [CCSprite spriteWithFile:@"staripad.png"];
    background.anchorPoint= ccp(0,0);
    [self addChild:background z:0];
} else {
    background = [CCSprite spriteWithFile:@"mars_sample.jpg"];
    background.anchorPoint= ccp(0,0);
    [self addChild:background z:0];
    [self schedule:@selector(backgroundmoving:) interval:1/30];
}
Run Code Online (Sandbox Code Playgroud)

请给我一些建议,它将如何运作.谢谢大家

问候,

Tauseef Khan

Nie*_*tle 2

检查您background.position = ccp( 0, bk_f )是否backgroundmoving将坐标的 Y 值设置为固定值bk_f。我假设您想要更改 X 值以滚动背景图像background.position = ccp( bk_f, 0 )

dt我假设用于提供移动背景图像的参数backgroundmoving未使用。

确保使用 autosize 属性将背景视图设置为展开以适合其超级视图。

检查背景视图的框架属性中的原点 - 检查它是否位于屏幕顶部。

我会在背景 UIImageView 后面添加一个普通的 UIView 并将其颜色设置为绿色或其他一些刺眼的颜色。这样您就可以直观地确认视图所覆盖的房地产。