2016-08-09 4 views
1

ココスクリエーターで背景画像をどのように繰り返し効果で設定できますか?ココスクリエーターの背景画像の反復効果

文字が動いている場合、バックイメージは後方に流れる必要がありますが、デバイスサイズのイメージファイルを1つ使用してバックグラウンドを繰り返し繰り返していきたいと思います。

答えて

1

私はアンカー0,0、キャンバスサイズ(キャンバス内に配置されていない画像)と同じであると仮定して、2つの背景画像を順に並べて配置することでこれを行うことができると思います。両方の画像に適用されたこのスクリプトは、その効果を最も単純な形で達成することができます。

cc.Class({ 
 
    extends: cc.Component, 
 

 
    properties: { 
 
     // speed of scrolling 
 
     speed: 0, 
 
     // reset to position 
 
     bgwidth: 0 
 
    }, 
 

 
    // use this for initialization 
 
    onLoad: function() { 
 
    }, 
 

 
    // called every frame, uncomment this function to activate update callback 
 
    update: function (dt) { 
 
     var x = this.node.x; 
 
     x -= this.speed * dt; 
 
     if (x <= -this.bgwidth) { 
 
      x += this.bgwidth*2; 
 
     } 
 
     this.node.x = x; 
 
    }, 
 
});