0
我正在使用cocos2d並嘗試使背景流動的效果... 所以我將代碼放在下面。 但有一些問題。 當時間到了,兩幅圖像之間的距離比第一次更大。 這是爲什麼? 我不明白這一點,任何人幫助我? 錯誤在哪裏? 代碼如下。使用cocos2d製作流動背景效果的問題iPhone
- (無效)啓動畫面:(ccTime)dt的 {
mBackgroundFar.position = ccp(mBackgroundFar.position.x - 50*dt , mBackgroundFar.position.y);
if (mBackgroundFar.position.x < -SCREEN_WIDTH * 2)
[mBackgroundFar setPosition:ccp(SCREEN_WIDTH*2 , mBackgroundFar.position.y)];
mBackgroundFar1.position = ccp(mBackgroundFar1.position.x - 50*dt , mBackgroundFar1.position.y);
if (mBackgroundFar1.position.x < -SCREEN_WIDTH * 2)
[mBackgroundFar1 setPosition:ccp(SCREEN_WIDTH*2 , mBackgroundFar1.position.y)];
mBackgroundMiddle.position = ccp(mBackgroundMiddle.position.x - 150*dt , mBackgroundMiddle.position.y);
if (mBackgroundMiddle.position.x < -SCREEN_WIDTH * 2)
[mBackgroundMiddle setPosition:ccp(SCREEN_WIDTH*2 , mBackgroundMiddle.position.y)];
mBackgroundMiddle1.position = ccp(mBackgroundMiddle1.position.x - 150*dt , mBackgroundMiddle1.position.y);
if (mBackgroundMiddle1.position.x < -SCREEN_WIDTH * 2)
[mBackgroundMiddle1 setPosition:ccp(SCREEN_WIDTH*2 , mBackgroundMiddle1.position.y)];
mBackgroundNear.position = ccp(mBackgroundNear.position.x - 250*dt , mBackgroundNear.position.y);
if (mBackgroundNear.position.x < -SCREEN_WIDTH * 2)
[mBackgroundNear setPosition:ccp(SCREEN_WIDTH*2 , mBackgroundNear.position.y)];
mBackgroundNear1.position = ccp(mBackgroundNear1.position.x - 250*dt , mBackgroundNear1.position.y);
if (mBackgroundNear1.position.x < -SCREEN_WIDTH * 2)
[mBackgroundNear1 setPosition:ccp(SCREEN_WIDTH*2 , mBackgroundNear1.position.y)];
}
在這裏,圖像大小是2 * iphone(480 * 2)的屏幕寬度,所有的那。
好的,我明白你的答案。我的圖像是否沒有像素計算?我認爲按照像素縮放我的圖像。那麼上面的代碼不是基於每個像素? – user1304842