![](/img/trans.png)
[英]UIViewContentModeScaleAspectFill of UIimageview working proper in iphone 4, but not in iphone4s
[英]“BackgroundMoving” Code is not Working in iPhone4S
當我在設備上測試我的應用程序(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);
}
當我將“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];
}
請給我一些建議,它將如何運作。 謝謝大家
問候,
Tauseef Khan
在backgroundmoving
檢查background.position = ccp( 0, bk_f )
是否將坐標的Y值設置為固定值bk_f
。 我假設你想要改變的X值是為了滾動背景圖像, background.position = ccp( bk_f, 0 )
。
我假設的參數dt
to backgroundmoving
是不使用提供移動的背景圖像。
確保使用自動調整大小屬性將背景視圖設置為展開以適合其超級視圖。
檢查背景視圖的frame屬性中的原點 - 檢查它是否位於屏幕頂部。
我會在你的背景UIImageView后面添加一個簡單的UIView,並將它的顏色設置為綠色或其他一些粗糙的顏色。 通過這種方式,您可以直觀地確認視圖所涵蓋的房地產。
//in .h file int bk_f=240;
-(void)backgroundmoving:(ccTime)dt
{
bk_f=bk_f-5;
if(bk_f<=0)
{
background.position = ccp( 240,160);
bk_f=240;
}
else
{
background.position = ccp( bk_f,160);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.