Advertisement
Guest User

Untitled

a guest
Feb 25th, 2020
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. const config = {
  2. type: Phaser.WEBGL,
  3. width: 375,
  4. height: 812,
  5. scene: {
  6. preload: preload,
  7. create: create,
  8. update: update
  9. }
  10. }
  11. function preload() {
  12. this.load.image('tiles', '../pt.png');
  13. this.load.tilemapTiledJSON('tilemap', '../final.json');
  14. var url = 'https://raw.githubusercontent.com/rexrainbow/phaser3-rex-notes/master/dist/rexpinchplugin.min.js';
  15. this.load.plugin('rexpinchplugin', url, true);
  16. }
  17.  
  18. function create() {
  19. window.addEventListener('resize', resize);
  20. resize();
  21. this.add.image(0, 0, 'map').setOrigin(0);
  22.  
  23. var map = this.make.tilemap({ key: 'tilemap' });
  24.  
  25. var tiles = map.addTilesetImage('pt', 'tiles');
  26.  
  27. const layer = map.createStaticLayer(0, tiles);
  28. // const layer1 = map.createStaticLayer(1, tiles);
  29.  
  30. var cam = this.cameras.main;
  31. // cam.setBounds(0, 0, map.displayWidth, map.displayHeight);
  32.  
  33. this.input.on('pointermove', function (p) {
  34. if (!p.isDown) return;
  35. cam.scrollX -= (p.position.x - p.prevPosition.x) / 4;
  36. cam.scrollY -= (p.position.y - p.prevPosition.y) / 4;
  37. });
  38. }
  39.  
  40. function update() {
  41. }
  42.  
  43. function resize() {
  44. var canvas = game.canvas, width = window.innerWidth, height = window.innerHeight;
  45. var wratio = width / height, ratio = canvas.width / canvas.height;
  46.  
  47. if (wratio < ratio) {
  48. canvas.style.width = width + "px";
  49. canvas.style.height = (width / ratio) + "px";
  50. } else {
  51. canvas.style.width = (height * ratio) + "px";
  52. canvas.style.height = height + "px";
  53. }
  54. }
  55.  
  56. window.game = new Phaser.Game(config);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement