javascript - 移相器滚动背景

标签 javascript html phaser-framework

我的目标是制作一个比屏幕更大的 Sprite ,并让用户滚动查看它的不同部分,所以我想问 Phaser 是否有任何 Sprite eventListener 功能,例如:

    var canvas = window.document.getElementsByTagName('canvas')[0],
        prevX = 0, prevY = 0, mouseDown = false;

Canvas 可以用作

    canvas.addEventListener('mousedown',function(e){
    });

   canvas.addEventListener('mousemove',function(e){
    });

最佳答案

这是我的做法。

在您的更新函数中:

if (this.game.input.activePointer.isDown) { 
  if (this.game.origDragPoint) {    
    // move the camera by the amount the mouse has moved since last update
    this.game.camera.x += this.game.origDragPoint.x - this.game.input.activePointer.position.x;
    this.game.camera.y += this.game.origDragPoint.y - this.game.input.activePointer.position.y;
  }
  // set new drag origin to current position
  this.game.origDragPoint = this.game.input.activePointer.position.clone();
}
else {
  this.game.origDragPoint = null;
}

关于javascript - 移相器滚动背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37902960/

相关文章:

javascript - 在 Phaser 3 中设置快照的位置

reactjs - Next.js( react )+ Phaser : ReferenceError: navigator is not defined

javascript - Angular Material md-slider : Vertical Slider will not work in md-sidenav

javascript - mysql实现流读和流插入

javascript - 禁用 jQuery 窗口大小功能

HTML+CSS 工具提示 : Weird behavior in table with rowspan

javascript - 从 jQuery 转换为 JavaScript

javascript - 如何在 Angular Js 中使用 name 或 id 属性验证表单

css - 如何叠加两个 div 并使它们具有相同的高度?

Javascript Phaser 跨域错误