Pixi.js viewport follow object












1















I'm making a simple game where a user walks around with a person. The person's gun will always be pointing the mouse. What I want is to allow the person to walk outside the viewport, with the viewport adapting to this. The viewport should always have the person in the middle. I already tried this library, but I couldn't get it to work. A good example of what I mean is Agar.io, where the player always sees himself in the middle of the viewport, and everything around him moves.



Does anyone have a clue how I should do this with Pixi.js?



My code:



    <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Hello World</title>
<style>
canvas{border:2px solid #000;}
</style>
</head>
<script src="pixi.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<body>
<script type="text/javascript">
function keyboard(value) {
let key = {};
key.value = value;
key.isDown = false;
key.isUp = true;
key.press = undefined;
key.release = undefined;
//The `downHandler`
key.downHandler = event => {
if (event.key === key.value) {
if (key.isUp && key.press) key.press();
key.isDown = true;
key.isUp = false;
event.preventDefault();
}
};

//The `upHandler`
key.upHandler = event => {
if (event.key === key.value) {
if (key.isDown && key.release) key.release();
key.isDown = false;
key.isUp = true;
event.preventDefault();
}
};

//Attach event listeners
const downListener = key.downHandler.bind(key);
const upListener = key.upHandler.bind(key);

window.addEventListener(
"keydown", downListener, false
);
window.addEventListener(
"keyup", upListener, false
);

// Detach event listeners
key.unsubscribe = () => {
window.removeEventListener("keydown", downListener);
window.removeEventListener("keyup", upListener);
};
return key;
}
//Aliases
let Application = PIXI.Application,
loader = PIXI.loader,
resources = PIXI.loader.resources,
Sprite = PIXI.Sprite;

//Create a Pixi Application
let app = new Application();
app.renderer.backgroundColor = 0xffffff;

//Add the canvas that Pixi automatically created for you to the HTML document
document.body.appendChild(app.view);

//load an image and run the `setup` function when it's done
loader
.add([
"sprite.png",
"img/walking/walking1.png",
"img/walking/walking2.png"
])
.load(setup);

let alienImages = ["img/walking/walking1.png","img/walking/walking2.png","img/walking/walking3.png","img/walking/walking4.png","img/walking/walking5.png","img/walking/walking6.png","img/walking/walking7.png","img/walking/walking8.png"];
let textureArray = ;

for (let i=0; i < 8; i++)
{
let texture = PIXI.Texture.fromImage(alienImages[i]);
textureArray.push(texture);
};

console.log(textureArray);

let cat;
let pixie = new PIXI.MovieClip(textureArray);
let radian;
let radianLast;
let mouseX;
let mouseY;
let left = keyboard("a"),
up = keyboard("w"),
right = keyboard("d"),
down = keyboard("s");

function checkIfAnimationStop(){
if(!right.isDown && !left.isDown && !down.isDown && !up.isDown){
pixie.gotoAndStop(0);
}
}

//This `setup` function will run when the image has loaded
function setup() {
//Create the cat sprite
cat = new Sprite(resources["sprite.png"].texture);
//cat.anchor.set(84.5, 115.5);
pixie.vx = 0;
pixie.vy = 0;

//Add the cat to the stage
pixie.position.set(32, 32);
app.stage.addChild(pixie);
pixie.animationSpeed = 0.2;

left.press = () => {
//Change the cat's velocity when the key is pressed
pixie.play();
pixie.vx = -4;
};

//Left arrow key `release` method
left.release = () => {
//If the left arrow has been released, and the right arrow isn't down,
//and the cat isn't moving vertically:
//Stop the cat
if (!right.isDown) {
pixie.vx = 0;
}
left.isDown = false;
checkIfAnimationStop();
};

//Up
up.press = () => {
pixie.play();
pixie.vy = -4;
};
up.release = () => {
if (!down.isDown) {
pixie.vy = 0;
}
up.isDown = false;
checkIfAnimationStop();
};

//Right
right.press = () => {
pixie.play();
pixie.vx = 4;
};
right.release = () => {
if (!left.isDown) {
pixie.vx = 0;
}
right.isDown = false;
checkIfAnimationStop();
};

//Down
down.press = () => {
pixie.play();
pixie.vy = 4;
};
down.release = () => {
if (!up.isDown) {
pixie.vy = 0;
}
down.isDown = false;
checkIfAnimationStop();
};

pixie.rotation = 0.5;

state = play;

app.ticker.add(delta => gameLoop(delta));
}

function gameLoop(delta){
state(delta);

}

function play(delta){
pixie.anchor.x = 0.9;
pixie.anchor.y = 0.5;
$(document).mousemove(function(e){
mouseX = e.pageX;
mouseY = e.pageY;
radianLast = radian;
});
radian = Math.atan2(mouseX-pixie.x,-(mouseY-pixie.y));
if((radian - pixie.rotation) > 0){
if((radian - pixie.rotation) > 3.14){
pixie.rotation -= 0.05;
if(pixie.rotation < -3.1){
pixie.rotation = 3.13;
}
} else {
pixie.rotation += 0.05;
}
}
if((radian - pixie.rotation) < 0){
if((radian - pixie.rotation) < -3.14){
pixie.rotation += 0.05;
if(pixie.rotation > 3.1){
pixie.rotation = -3.13;
}
} else {
pixie.rotation -= 0.05;
}
}
$("#angle").text(pixie.vx);
$("#info").text(pixie.vy);
if(pixie.vx != 0 && pixie.vy != 0){
if(pixie.vx > 0){
pixie.vx2 = 2.828;
} else if(pixie.vx < 0){
pixie.vx2 = -2.828;
}
if(pixie.vy > 0){
pixie.vy2 = 2.828;
} else if(pixie.vy < 0){
pixie.vy2 = -2.828;
}
pixie.x += pixie.vx2;
pixie.y += pixie.vy2;
$("#angle").text(pixie.vx2);
$("#info").text(pixie.vy2);
} else {
pixie.x += pixie.vx;
pixie.y += pixie.vy;
}
}
</script>
<div id="angle"></div>
<div id="info"></div>
<div id="t"></div>
</body>
</html>









share|improve this question



























    1















    I'm making a simple game where a user walks around with a person. The person's gun will always be pointing the mouse. What I want is to allow the person to walk outside the viewport, with the viewport adapting to this. The viewport should always have the person in the middle. I already tried this library, but I couldn't get it to work. A good example of what I mean is Agar.io, where the player always sees himself in the middle of the viewport, and everything around him moves.



    Does anyone have a clue how I should do this with Pixi.js?



    My code:



        <!doctype html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Hello World</title>
    <style>
    canvas{border:2px solid #000;}
    </style>
    </head>
    <script src="pixi.min.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <body>
    <script type="text/javascript">
    function keyboard(value) {
    let key = {};
    key.value = value;
    key.isDown = false;
    key.isUp = true;
    key.press = undefined;
    key.release = undefined;
    //The `downHandler`
    key.downHandler = event => {
    if (event.key === key.value) {
    if (key.isUp && key.press) key.press();
    key.isDown = true;
    key.isUp = false;
    event.preventDefault();
    }
    };

    //The `upHandler`
    key.upHandler = event => {
    if (event.key === key.value) {
    if (key.isDown && key.release) key.release();
    key.isDown = false;
    key.isUp = true;
    event.preventDefault();
    }
    };

    //Attach event listeners
    const downListener = key.downHandler.bind(key);
    const upListener = key.upHandler.bind(key);

    window.addEventListener(
    "keydown", downListener, false
    );
    window.addEventListener(
    "keyup", upListener, false
    );

    // Detach event listeners
    key.unsubscribe = () => {
    window.removeEventListener("keydown", downListener);
    window.removeEventListener("keyup", upListener);
    };
    return key;
    }
    //Aliases
    let Application = PIXI.Application,
    loader = PIXI.loader,
    resources = PIXI.loader.resources,
    Sprite = PIXI.Sprite;

    //Create a Pixi Application
    let app = new Application();
    app.renderer.backgroundColor = 0xffffff;

    //Add the canvas that Pixi automatically created for you to the HTML document
    document.body.appendChild(app.view);

    //load an image and run the `setup` function when it's done
    loader
    .add([
    "sprite.png",
    "img/walking/walking1.png",
    "img/walking/walking2.png"
    ])
    .load(setup);

    let alienImages = ["img/walking/walking1.png","img/walking/walking2.png","img/walking/walking3.png","img/walking/walking4.png","img/walking/walking5.png","img/walking/walking6.png","img/walking/walking7.png","img/walking/walking8.png"];
    let textureArray = ;

    for (let i=0; i < 8; i++)
    {
    let texture = PIXI.Texture.fromImage(alienImages[i]);
    textureArray.push(texture);
    };

    console.log(textureArray);

    let cat;
    let pixie = new PIXI.MovieClip(textureArray);
    let radian;
    let radianLast;
    let mouseX;
    let mouseY;
    let left = keyboard("a"),
    up = keyboard("w"),
    right = keyboard("d"),
    down = keyboard("s");

    function checkIfAnimationStop(){
    if(!right.isDown && !left.isDown && !down.isDown && !up.isDown){
    pixie.gotoAndStop(0);
    }
    }

    //This `setup` function will run when the image has loaded
    function setup() {
    //Create the cat sprite
    cat = new Sprite(resources["sprite.png"].texture);
    //cat.anchor.set(84.5, 115.5);
    pixie.vx = 0;
    pixie.vy = 0;

    //Add the cat to the stage
    pixie.position.set(32, 32);
    app.stage.addChild(pixie);
    pixie.animationSpeed = 0.2;

    left.press = () => {
    //Change the cat's velocity when the key is pressed
    pixie.play();
    pixie.vx = -4;
    };

    //Left arrow key `release` method
    left.release = () => {
    //If the left arrow has been released, and the right arrow isn't down,
    //and the cat isn't moving vertically:
    //Stop the cat
    if (!right.isDown) {
    pixie.vx = 0;
    }
    left.isDown = false;
    checkIfAnimationStop();
    };

    //Up
    up.press = () => {
    pixie.play();
    pixie.vy = -4;
    };
    up.release = () => {
    if (!down.isDown) {
    pixie.vy = 0;
    }
    up.isDown = false;
    checkIfAnimationStop();
    };

    //Right
    right.press = () => {
    pixie.play();
    pixie.vx = 4;
    };
    right.release = () => {
    if (!left.isDown) {
    pixie.vx = 0;
    }
    right.isDown = false;
    checkIfAnimationStop();
    };

    //Down
    down.press = () => {
    pixie.play();
    pixie.vy = 4;
    };
    down.release = () => {
    if (!up.isDown) {
    pixie.vy = 0;
    }
    down.isDown = false;
    checkIfAnimationStop();
    };

    pixie.rotation = 0.5;

    state = play;

    app.ticker.add(delta => gameLoop(delta));
    }

    function gameLoop(delta){
    state(delta);

    }

    function play(delta){
    pixie.anchor.x = 0.9;
    pixie.anchor.y = 0.5;
    $(document).mousemove(function(e){
    mouseX = e.pageX;
    mouseY = e.pageY;
    radianLast = radian;
    });
    radian = Math.atan2(mouseX-pixie.x,-(mouseY-pixie.y));
    if((radian - pixie.rotation) > 0){
    if((radian - pixie.rotation) > 3.14){
    pixie.rotation -= 0.05;
    if(pixie.rotation < -3.1){
    pixie.rotation = 3.13;
    }
    } else {
    pixie.rotation += 0.05;
    }
    }
    if((radian - pixie.rotation) < 0){
    if((radian - pixie.rotation) < -3.14){
    pixie.rotation += 0.05;
    if(pixie.rotation > 3.1){
    pixie.rotation = -3.13;
    }
    } else {
    pixie.rotation -= 0.05;
    }
    }
    $("#angle").text(pixie.vx);
    $("#info").text(pixie.vy);
    if(pixie.vx != 0 && pixie.vy != 0){
    if(pixie.vx > 0){
    pixie.vx2 = 2.828;
    } else if(pixie.vx < 0){
    pixie.vx2 = -2.828;
    }
    if(pixie.vy > 0){
    pixie.vy2 = 2.828;
    } else if(pixie.vy < 0){
    pixie.vy2 = -2.828;
    }
    pixie.x += pixie.vx2;
    pixie.y += pixie.vy2;
    $("#angle").text(pixie.vx2);
    $("#info").text(pixie.vy2);
    } else {
    pixie.x += pixie.vx;
    pixie.y += pixie.vy;
    }
    }
    </script>
    <div id="angle"></div>
    <div id="info"></div>
    <div id="t"></div>
    </body>
    </html>









    share|improve this question

























      1












      1








      1








      I'm making a simple game where a user walks around with a person. The person's gun will always be pointing the mouse. What I want is to allow the person to walk outside the viewport, with the viewport adapting to this. The viewport should always have the person in the middle. I already tried this library, but I couldn't get it to work. A good example of what I mean is Agar.io, where the player always sees himself in the middle of the viewport, and everything around him moves.



      Does anyone have a clue how I should do this with Pixi.js?



      My code:



          <!doctype html>
      <html>
      <head>
      <meta charset="utf-8">
      <title>Hello World</title>
      <style>
      canvas{border:2px solid #000;}
      </style>
      </head>
      <script src="pixi.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <body>
      <script type="text/javascript">
      function keyboard(value) {
      let key = {};
      key.value = value;
      key.isDown = false;
      key.isUp = true;
      key.press = undefined;
      key.release = undefined;
      //The `downHandler`
      key.downHandler = event => {
      if (event.key === key.value) {
      if (key.isUp && key.press) key.press();
      key.isDown = true;
      key.isUp = false;
      event.preventDefault();
      }
      };

      //The `upHandler`
      key.upHandler = event => {
      if (event.key === key.value) {
      if (key.isDown && key.release) key.release();
      key.isDown = false;
      key.isUp = true;
      event.preventDefault();
      }
      };

      //Attach event listeners
      const downListener = key.downHandler.bind(key);
      const upListener = key.upHandler.bind(key);

      window.addEventListener(
      "keydown", downListener, false
      );
      window.addEventListener(
      "keyup", upListener, false
      );

      // Detach event listeners
      key.unsubscribe = () => {
      window.removeEventListener("keydown", downListener);
      window.removeEventListener("keyup", upListener);
      };
      return key;
      }
      //Aliases
      let Application = PIXI.Application,
      loader = PIXI.loader,
      resources = PIXI.loader.resources,
      Sprite = PIXI.Sprite;

      //Create a Pixi Application
      let app = new Application();
      app.renderer.backgroundColor = 0xffffff;

      //Add the canvas that Pixi automatically created for you to the HTML document
      document.body.appendChild(app.view);

      //load an image and run the `setup` function when it's done
      loader
      .add([
      "sprite.png",
      "img/walking/walking1.png",
      "img/walking/walking2.png"
      ])
      .load(setup);

      let alienImages = ["img/walking/walking1.png","img/walking/walking2.png","img/walking/walking3.png","img/walking/walking4.png","img/walking/walking5.png","img/walking/walking6.png","img/walking/walking7.png","img/walking/walking8.png"];
      let textureArray = ;

      for (let i=0; i < 8; i++)
      {
      let texture = PIXI.Texture.fromImage(alienImages[i]);
      textureArray.push(texture);
      };

      console.log(textureArray);

      let cat;
      let pixie = new PIXI.MovieClip(textureArray);
      let radian;
      let radianLast;
      let mouseX;
      let mouseY;
      let left = keyboard("a"),
      up = keyboard("w"),
      right = keyboard("d"),
      down = keyboard("s");

      function checkIfAnimationStop(){
      if(!right.isDown && !left.isDown && !down.isDown && !up.isDown){
      pixie.gotoAndStop(0);
      }
      }

      //This `setup` function will run when the image has loaded
      function setup() {
      //Create the cat sprite
      cat = new Sprite(resources["sprite.png"].texture);
      //cat.anchor.set(84.5, 115.5);
      pixie.vx = 0;
      pixie.vy = 0;

      //Add the cat to the stage
      pixie.position.set(32, 32);
      app.stage.addChild(pixie);
      pixie.animationSpeed = 0.2;

      left.press = () => {
      //Change the cat's velocity when the key is pressed
      pixie.play();
      pixie.vx = -4;
      };

      //Left arrow key `release` method
      left.release = () => {
      //If the left arrow has been released, and the right arrow isn't down,
      //and the cat isn't moving vertically:
      //Stop the cat
      if (!right.isDown) {
      pixie.vx = 0;
      }
      left.isDown = false;
      checkIfAnimationStop();
      };

      //Up
      up.press = () => {
      pixie.play();
      pixie.vy = -4;
      };
      up.release = () => {
      if (!down.isDown) {
      pixie.vy = 0;
      }
      up.isDown = false;
      checkIfAnimationStop();
      };

      //Right
      right.press = () => {
      pixie.play();
      pixie.vx = 4;
      };
      right.release = () => {
      if (!left.isDown) {
      pixie.vx = 0;
      }
      right.isDown = false;
      checkIfAnimationStop();
      };

      //Down
      down.press = () => {
      pixie.play();
      pixie.vy = 4;
      };
      down.release = () => {
      if (!up.isDown) {
      pixie.vy = 0;
      }
      down.isDown = false;
      checkIfAnimationStop();
      };

      pixie.rotation = 0.5;

      state = play;

      app.ticker.add(delta => gameLoop(delta));
      }

      function gameLoop(delta){
      state(delta);

      }

      function play(delta){
      pixie.anchor.x = 0.9;
      pixie.anchor.y = 0.5;
      $(document).mousemove(function(e){
      mouseX = e.pageX;
      mouseY = e.pageY;
      radianLast = radian;
      });
      radian = Math.atan2(mouseX-pixie.x,-(mouseY-pixie.y));
      if((radian - pixie.rotation) > 0){
      if((radian - pixie.rotation) > 3.14){
      pixie.rotation -= 0.05;
      if(pixie.rotation < -3.1){
      pixie.rotation = 3.13;
      }
      } else {
      pixie.rotation += 0.05;
      }
      }
      if((radian - pixie.rotation) < 0){
      if((radian - pixie.rotation) < -3.14){
      pixie.rotation += 0.05;
      if(pixie.rotation > 3.1){
      pixie.rotation = -3.13;
      }
      } else {
      pixie.rotation -= 0.05;
      }
      }
      $("#angle").text(pixie.vx);
      $("#info").text(pixie.vy);
      if(pixie.vx != 0 && pixie.vy != 0){
      if(pixie.vx > 0){
      pixie.vx2 = 2.828;
      } else if(pixie.vx < 0){
      pixie.vx2 = -2.828;
      }
      if(pixie.vy > 0){
      pixie.vy2 = 2.828;
      } else if(pixie.vy < 0){
      pixie.vy2 = -2.828;
      }
      pixie.x += pixie.vx2;
      pixie.y += pixie.vy2;
      $("#angle").text(pixie.vx2);
      $("#info").text(pixie.vy2);
      } else {
      pixie.x += pixie.vx;
      pixie.y += pixie.vy;
      }
      }
      </script>
      <div id="angle"></div>
      <div id="info"></div>
      <div id="t"></div>
      </body>
      </html>









      share|improve this question














      I'm making a simple game where a user walks around with a person. The person's gun will always be pointing the mouse. What I want is to allow the person to walk outside the viewport, with the viewport adapting to this. The viewport should always have the person in the middle. I already tried this library, but I couldn't get it to work. A good example of what I mean is Agar.io, where the player always sees himself in the middle of the viewport, and everything around him moves.



      Does anyone have a clue how I should do this with Pixi.js?



      My code:



          <!doctype html>
      <html>
      <head>
      <meta charset="utf-8">
      <title>Hello World</title>
      <style>
      canvas{border:2px solid #000;}
      </style>
      </head>
      <script src="pixi.min.js"></script>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <body>
      <script type="text/javascript">
      function keyboard(value) {
      let key = {};
      key.value = value;
      key.isDown = false;
      key.isUp = true;
      key.press = undefined;
      key.release = undefined;
      //The `downHandler`
      key.downHandler = event => {
      if (event.key === key.value) {
      if (key.isUp && key.press) key.press();
      key.isDown = true;
      key.isUp = false;
      event.preventDefault();
      }
      };

      //The `upHandler`
      key.upHandler = event => {
      if (event.key === key.value) {
      if (key.isDown && key.release) key.release();
      key.isDown = false;
      key.isUp = true;
      event.preventDefault();
      }
      };

      //Attach event listeners
      const downListener = key.downHandler.bind(key);
      const upListener = key.upHandler.bind(key);

      window.addEventListener(
      "keydown", downListener, false
      );
      window.addEventListener(
      "keyup", upListener, false
      );

      // Detach event listeners
      key.unsubscribe = () => {
      window.removeEventListener("keydown", downListener);
      window.removeEventListener("keyup", upListener);
      };
      return key;
      }
      //Aliases
      let Application = PIXI.Application,
      loader = PIXI.loader,
      resources = PIXI.loader.resources,
      Sprite = PIXI.Sprite;

      //Create a Pixi Application
      let app = new Application();
      app.renderer.backgroundColor = 0xffffff;

      //Add the canvas that Pixi automatically created for you to the HTML document
      document.body.appendChild(app.view);

      //load an image and run the `setup` function when it's done
      loader
      .add([
      "sprite.png",
      "img/walking/walking1.png",
      "img/walking/walking2.png"
      ])
      .load(setup);

      let alienImages = ["img/walking/walking1.png","img/walking/walking2.png","img/walking/walking3.png","img/walking/walking4.png","img/walking/walking5.png","img/walking/walking6.png","img/walking/walking7.png","img/walking/walking8.png"];
      let textureArray = ;

      for (let i=0; i < 8; i++)
      {
      let texture = PIXI.Texture.fromImage(alienImages[i]);
      textureArray.push(texture);
      };

      console.log(textureArray);

      let cat;
      let pixie = new PIXI.MovieClip(textureArray);
      let radian;
      let radianLast;
      let mouseX;
      let mouseY;
      let left = keyboard("a"),
      up = keyboard("w"),
      right = keyboard("d"),
      down = keyboard("s");

      function checkIfAnimationStop(){
      if(!right.isDown && !left.isDown && !down.isDown && !up.isDown){
      pixie.gotoAndStop(0);
      }
      }

      //This `setup` function will run when the image has loaded
      function setup() {
      //Create the cat sprite
      cat = new Sprite(resources["sprite.png"].texture);
      //cat.anchor.set(84.5, 115.5);
      pixie.vx = 0;
      pixie.vy = 0;

      //Add the cat to the stage
      pixie.position.set(32, 32);
      app.stage.addChild(pixie);
      pixie.animationSpeed = 0.2;

      left.press = () => {
      //Change the cat's velocity when the key is pressed
      pixie.play();
      pixie.vx = -4;
      };

      //Left arrow key `release` method
      left.release = () => {
      //If the left arrow has been released, and the right arrow isn't down,
      //and the cat isn't moving vertically:
      //Stop the cat
      if (!right.isDown) {
      pixie.vx = 0;
      }
      left.isDown = false;
      checkIfAnimationStop();
      };

      //Up
      up.press = () => {
      pixie.play();
      pixie.vy = -4;
      };
      up.release = () => {
      if (!down.isDown) {
      pixie.vy = 0;
      }
      up.isDown = false;
      checkIfAnimationStop();
      };

      //Right
      right.press = () => {
      pixie.play();
      pixie.vx = 4;
      };
      right.release = () => {
      if (!left.isDown) {
      pixie.vx = 0;
      }
      right.isDown = false;
      checkIfAnimationStop();
      };

      //Down
      down.press = () => {
      pixie.play();
      pixie.vy = 4;
      };
      down.release = () => {
      if (!up.isDown) {
      pixie.vy = 0;
      }
      down.isDown = false;
      checkIfAnimationStop();
      };

      pixie.rotation = 0.5;

      state = play;

      app.ticker.add(delta => gameLoop(delta));
      }

      function gameLoop(delta){
      state(delta);

      }

      function play(delta){
      pixie.anchor.x = 0.9;
      pixie.anchor.y = 0.5;
      $(document).mousemove(function(e){
      mouseX = e.pageX;
      mouseY = e.pageY;
      radianLast = radian;
      });
      radian = Math.atan2(mouseX-pixie.x,-(mouseY-pixie.y));
      if((radian - pixie.rotation) > 0){
      if((radian - pixie.rotation) > 3.14){
      pixie.rotation -= 0.05;
      if(pixie.rotation < -3.1){
      pixie.rotation = 3.13;
      }
      } else {
      pixie.rotation += 0.05;
      }
      }
      if((radian - pixie.rotation) < 0){
      if((radian - pixie.rotation) < -3.14){
      pixie.rotation += 0.05;
      if(pixie.rotation > 3.1){
      pixie.rotation = -3.13;
      }
      } else {
      pixie.rotation -= 0.05;
      }
      }
      $("#angle").text(pixie.vx);
      $("#info").text(pixie.vy);
      if(pixie.vx != 0 && pixie.vy != 0){
      if(pixie.vx > 0){
      pixie.vx2 = 2.828;
      } else if(pixie.vx < 0){
      pixie.vx2 = -2.828;
      }
      if(pixie.vy > 0){
      pixie.vy2 = 2.828;
      } else if(pixie.vy < 0){
      pixie.vy2 = -2.828;
      }
      pixie.x += pixie.vx2;
      pixie.y += pixie.vy2;
      $("#angle").text(pixie.vx2);
      $("#info").text(pixie.vy2);
      } else {
      pixie.x += pixie.vx;
      pixie.y += pixie.vy;
      }
      }
      </script>
      <div id="angle"></div>
      <div id="info"></div>
      <div id="t"></div>
      </body>
      </html>






      javascript pixi.js






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 22 '18 at 14:02









      P.YntemaP.Yntema

      224417




      224417
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432658%2fpixi-js-viewport-follow-object%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53432658%2fpixi-js-viewport-follow-object%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Wiesbaden

          Marschland

          Dieringhausen