创建无限滚动背景

时间:2016-07-11 13:41:38

标签: ios swift sprite-kit

我正在创建一个我正在创建的游戏的无限滚动背景。当我运行它时它会垂直滚动。我怎么能让它水平滚动?这是使其滚动的代码。

override func update(currentTime: NSTimeInterval) {

    background.position = CGPoint(x: background.position.x - 4, y: background.position.y)
    background2.position = CGPoint(x: background2.position.x - 4, y: background2.position.y)

    //this creates an infinte scrolling background
    if (background.position.x < -background.size.width) {
        background.position = CGPointMake(background2.position.x + background2.size.width, background.position.y)
        }

    if (background2.position.x < -background2.size.width) {
        background2.position = CGPointMake(background.position.x + background.size.width, background2.position.y)
    }

}

2 个答案:

答案 0 :(得分:0)

这使得.x每次传递减少4次

background.position = CGPoint(x: background.position.x, y: background.position.y-4)
    background2.position = CGPoint(x: background2.position.x, y: background2.position.y-4)

将该增量移至.y

var availableTags = [
  "Perl",
  "PHP",
  "Python",
  "Ruby"
];
$('input#mainSearchBox').autocomplete({
  source: availableTags,
  minLength: 0
});

$('input#mainSearchBox').autocomplete("disable");

$('input#mainSearchBox').keyup(function(e) {

  var code = (e.keyCode ? e.keyCode : e.which);
  switch (code) {
    case 40: //down key
    case 38: //up key
    //add more cases for special buttons
      return;
  }

  var value = $('input#mainSearchBox').val();
  var last = value.substr(value.length - 1);
  if (last == "*") {
    var valToSearch = value.substr(0, value.length - 1);
    $('input#mainSearchBox').autocomplete("enable");
    $('input#mainSearchBox').autocomplete("search", valToSearch);
  } else {
    $('input#mainSearchBox').autocomplete("disable");
  }
});

作为额外的奖励....如果你想达到一种避免效果,你应该在后面的背景上使用较慢的增量。

答案 1 :(得分:0)

background.position = CGPointMake(0.0,0.0);