私は水平に2つの背景のimagsを移動させ、このボイド機能を持っていますが、私は上下方向に移動したい:私のコードにどうすればこれらの背景画像をcocos2dではなく横に移動できますか?
-(void) scroll:(ccTime)dt
{
//move 30*dt px vertically
if (background.position.x<background2.position.x){
background.position = ccp(background.position.x - 30*dt,background.contentSize.height/2);
background2.position = ccp(background.position.x+background.contentSize.width,background2.contentSize.height/2);
}else{
background2.position = ccp(background2.position.x- 30*dt,background2.contentSize.height/2);
background.position = ccp(background2.position.x+background2.contentSize.width ,background.contentSize.height/2);
}
//reset offscreen position
if (background.position.x <-background.contentSize.width/2)
{
background.position = ccp(background2.position.x+background2.contentSize.width,background.contentSize.width/2);
}else if (background2.position.x < -background2.contentSize.width/2)
{
background2.position = ccp(background.position.x+background.contentSize.width, background2.contentSize.width/2);
}
}
更新:
私はX-CO-を変更したくないので、縦座標は私がyを変えさせると思ったので、イメージは垂直に動くことができます!
-(void) scroll:(ccTime)dt
{
//move 30*dt px vertically
if (background.position.y<background2.position.y){
background.position = ccp(background.position.y - 30*dt,background.contentSize.width/2);
background2.position = ccp(background.position.x+background.contentSize.height,background2.contentSize.width/2);
}else{
background2.position = ccp(background2.position.y- 30*dt,background2.contentSize.width/2);
background.position = ccp(background2.position.y+background2.contentSize.height ,background.contentSize.width/2);
}
//reset offscreen position
if (background.position.y <-background.contentSize.width/2)
{
background.position = ccp(background2.position.y+background2.contentSize.height,background.contentSize.height/2);
}else if (background2.position.x < -background2.contentSize.height/2)
{
background2.position = ccp(background.position.y+background.contentSize.height, background2.contentSize.height/2);
}
}
しかし、それは私はちょうど第1の背景を取得し変更し、何のスクロールが行われていないされていると:((
バックグラウンドの初期化コード:cocos2dと私はドンは本当に新しい
//adding background sprites
background = [CCSprite spriteWithFile:@"bg.JPG"];
background2 = [CCSprite spriteWithFile:@"bg.JPG"];
[background.texture setAliasTexParameters];
[background2.texture setAliasTexParameters];
//position background sprites
background.position = ccp(background.contentSize.width/2,background.contentSize.height/2);
background2.position = ccp(0,size.height);
//schedule to move background sprites
[self schedule:@selector(scroll:)];
//adding them to the main layer
[self addChild:background z:0];
[self addChild:background2 z:0];
イム」を
私のコードを更新しました。しかし、私は静止画像を得る! – MidnightCoder
@MidnightCoder MDTのアドバイスは戦闘の半分であり、実際にビルドしてテストしていれば、MDTは彼らのアドバイスに欠けているものを認識するだろうと確信しています。 (私は自分でコードを実行しているわけではありません)あなたの例のより複雑な行を変更する方法についての私の記述を見てください...うまくいけば、それはより役に立ちます。 –
答えてくれてありがとう、私は何が起こっているのか理解していない、 'background.postion = ccp(bgOldX、bgNewY);' – MidnightCoder