Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 移相器滚动背景_Javascript_Html_Phaser Framework - Fatal编程技术网

Javascript 移相器滚动背景

Javascript 移相器滚动背景,javascript,html,phaser-framework,Javascript,Html,Phaser Framework,我的目标是使一个精灵比屏幕大,让用户滚动查看它的不同部分,因此我想问Phaser是否有任何精灵eventListener-功能,例如: var canvas = window.document.getElementsByTagName('canvas')[0], prevX = 0, prevY = 0, mouseDown = false; 画布可以用作 canvas.addEventListener('mousedown',function(e){

我的目标是使一个精灵比屏幕大,让用户滚动查看它的不同部分,因此我想问Phaser是否有任何精灵
eventListener
-功能,例如:

    var canvas = window.document.getElementsByTagName('canvas')[0],
        prevX = 0, prevY = 0, mouseDown = false;
画布可以用作

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

   canvas.addEventListener('mousemove',function(e){
    });
我是这样做的

在更新功能中:

if(this.game.input.activePointer.isDown){
如果(this.game.origDragPoint){
//按上次更新后鼠标移动的量移动相机
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;
}
//将新的拖动原点设置为当前位置
this.game.origDragPoint=this.game.input.activePointer.position.clone();
}
否则{
this.game.origDragPoint=null;
}

如果您可以使用摄像头,您可以尝试此Phaser 2插件:

使用此插件,您可以启用垂直和水平滚动来模拟滚动到Phaser使用的画布元素中,也可以在初始化插件之前自定义移动,例如:

var game = new Phaser.Game(400, 400, Phaser.AUTO, '', {
  init: function () {

    //Load the plugin
    this.game.kineticScrolling = this.game.plugins.add(Phaser.Plugin.KineticScrolling);
  },
  create: function () {

    //Configure the plugin
    this.game.kineticScrolling.configure({
      kineticMovement: true,
      timeConstantScroll: 325, //really mimic iOS
      horizontalScroll: true,
      verticalScroll: false,
      horizontalWheel: true,
      verticalWheel: false,
      deltaWheel: 40
    });

    //Starts the plugin
    this.game.kineticScrolling.start();

    //Changing the world size
    this.game.world.setBounds(0, 0, 800, 800);
  },
  stopScrolling: function () {
    //Stop the plugin
    this.game.kineticScrolling.stop();
  }
});
还有一个用于Phaser 3的分叉,检查GitHub的回购


关于这一点,Nicholls

这很好,唯一的问题是在移动设备上存在明显的性能问题。。在这一点上找不到更好的办法