Beispiel #1
0
 function Main(opt) {
   asset_loader = opt.asset_loader;
   PIXI.Stage.call(this, 0x194894, true);
   this.setupCanvas();
   this.loadAssets();
   this.initGameLoop();
 }
Beispiel #2
0
    constructor(width, height, gameMap, camera) {
        this._renderer = PIXI.autoDetectRenderer(width, height);
        this._stage = new PIXI.Stage(0x16181B);

        this._cameraLayer = new PIXI.DisplayObjectContainer();
        this._mapLayer = new PIXI.DisplayObjectContainer();
        this._entityLayer = new PIXI.DisplayObjectContainer();

        this._stage.addChild(this._cameraLayer);
        this._cameraLayer.addChild(this._mapLayer);
        this._cameraLayer.addChild(this._entityLayer);

        this._initializeMapLayer(gameMap);

        this._camera = camera;

        this._width = width;
        this._height = height;

        this._spriteCache = {};

        window.addEventListener("resize", () => this.resize());
        window.addEventListener("deviceOrientation", () => this.resize());
        this.resize();
    }
Beispiel #3
0
 .end(function (res) {
   var SVG = new DOMParser().parseFromString(res.text, 'text/xml')
   layers = svgToSprites(SVG)
   for (var i in layers) {
     stage.addChild(layers[i])
   }
   console.log(layers)
 })
Beispiel #4
0
 function Main() {
   PIXI.Stage.call(this, 0x000000, true);
   this.mousedown = this.touchstart = this.onScreenTouch;
   this.mouseup = this.touchend = this.onScreenTouchEnd;
   this.setupCanvas();
   this.loadAssets();
   this.initGameLoop();
 }
Beispiel #5
0
Datei: Game.js Projekt: gre/ld31
function Game (seed, controls, playername) {
  PIXI.Stage.call(this);
  PIXI.EventTarget.mixin(this);

  var world = new World();
  var cars = new SpawnerCollection();
  var particles = new SpawnerCollection();
  var map = new Map(seed, cars, particles);
  var deadCarrots = new PIXI.DisplayObjectContainer();
  var footprints = new PIXI.DisplayObjectContainer();
  var player = new Player(playername, footprints);
  player.controls = controls;
  var players = new PIXI.DisplayObjectContainer();
  var ui = new PIXI.DisplayObjectContainer();
  var score = new PIXI.Text("", { font: 'bold 20px '+font.name, fill: '#88B' });
  score.position.x = 10;
  score.position.y = 10;
  var life = new PIXI.Text("", {
    font: 'normal 20px '+font.name
  });
  life.position.x = conf.WIDTH - 60;
  life.position.y = 10;

  world.addChild(map);
  world.addChild(deadCarrots);
  world.addChild(footprints);
  world.addChild(players);
  world.addChild(player);
  world.addChild(cars);
  world.addChild(particles);

  ui.addChild(score);
  ui.addChild(life);

  this.addChild(world);
  this.addChild(ui);

  this.world = world;
  this.map = map;
  this.cars = cars;
  this.particles = particles;
  this.deadCarrots = deadCarrots;
  this.footprints = footprints;
  this.player = player;
  this.players = players;
  this.players.update = updateChildren;
  this.ui = ui;
  this.score = score;
  this.life = life;
  this.controls = controls;

  // Game states
  this.audio1 = audio.loop("/audio/1.ogg");
};
Beispiel #6
0
 loadMap(arr, width) {
   if (arr.length % width != 0) {
     throw new Error('map space count is not a multiple of width');
   }
   this.state = new PIXI.Stage();
   this.container = new PIXI.DisplayObjectContainer();
   this.container.scale.x = this.scale;
   this.container.scale.y = this.scale;
   this.stage.addChild(this.container);
   const map = [];
   for (let i = 0; i < arr.length; i++) {
     let graphics = map[i] = new PIXI.Graphics();
     // TODO gfx per space, walls height, etc.
     // mouseovers blah blah
     graphics.beginFill(0x00FF00);
     let col = i % width;
     let row = Math.floor(i / width);
     graphics.drawRect(col * this.scale, row * this.scale, this.scale, this.scale);
     graphics.endFill();
     this.container.addChild(graphics);
   }
 }
Beispiel #7
0
Particle.prototype = Object.create(PIXI.Graphics.prototype);
Particle.prototype.constructor = Particle;
Particle.prototype.hitBox = function () {
  return {
    x: this.x - this.pivot.x * this.scale.x,
    y: this.y - this.pivot.y * this.scale.y,
    width: this.width,
    height: this.height
  };
};
Particle.prototype.collides = spriteCollides;

var renderer = PIXI.autoDetectRenderer(800, 400);
document.body.appendChild(renderer.view);

var stage = new PIXI.Stage(0xFFFFFF);

var spawners = new PIXI.DisplayObjectContainer();
stage.addChild(spawners);

function spawn (i, random) {
  var clr = ~~(random() * 0xFF) << 16 | ~~(random() * 0xFF) << 8 | ~~(random() * 0xFF);
  var radius = ~~(5 + random() * 15);
  return new Particle(clr, radius);
}

var viewport = { x: 0, y: 0, width: 800, height: 400 };

[
  { seed: "a", spawn: spawn, pos: [50, 50], vel: 0.1, speed: 500, seq: [ 1, -1, 2, -1, 3, -1 ] },
  { seed: "b", spawn: spawn, pos: [400, 200], rotate: 0.2, vel: 0.05, speed: 200, seq: [5, -4, 6, -2, 2, -8], life: 60000, livingBound: viewport }
Beispiel #8
0
window.onload = function() {
  var eventBus = require('./utils/event_bus');
  var PIXI = require('pixi.js');
  window.PIXI = PIXI;
  var requestAnimFrame = (function() {
    return window.requestAnimationFrame ||
      window.webkitRequestAnimationFrame ||
      window.mozRequestAnimationFrame ||
      function(callback) {
        window.setTimeout(callback, 1000 / 60);
      };
  })();

  // create an new instance of a pixi stage
  var interactive = true;
  var stage = new PIXI.Stage(0x66FF99, interactive);
  window.stage = stage;

  var winSize = require('./utils/window_size');

  var config = require('./config');
  var bounds = config.bounds;
  var startX = bounds.x[1] / -2;
  var startY = bounds.y[1] / -2;

  // create a renderer instance
  // var renderer = new PIXI.CanvasRenderer(winSize.width, winSize.height);
  var renderer = PIXI.autoDetectRenderer(winSize.width, winSize.height);

  // add the renderer view element to the DOM
  document.body.appendChild(renderer.view);

  requestAnimFrame( animate );

  // create a texture from an image path
  var texture = PIXI.Texture.fromImage('imgs/bg.jpg');
  var tilingSprite = new PIXI.extras.TilingSprite(texture, winSize.width, winSize.height);
  stage.addChild(tilingSprite);

  var UpdateContainer = require('./classes/update_container');
  var stageContainer = new UpdateContainer();
  stage.addChild(stageContainer);

  var Grid = require('./classes/grid');
  var graphics = new Grid(0x2DC8D2, 0xFF0000, bounds);

  window.stage = stage;

  var dragZoom = require('./utils/drag_zoom');
  var gridPos = dragZoom(document, startX, startY, 1, bounds);
  window.gridPos = gridPos;

  var setPositions = function() {
    stageContainer.position.x = gridPos.x;
    stageContainer.position.y = gridPos.y;
    stageContainer.scale.x = gridPos.zoom;
    stageContainer.scale.y = gridPos.zoom;

    tilingSprite.tilePosition.x = gridPos.x * 0.8;
    tilingSprite.tilePosition.y = gridPos.y * 0.8;
    tilingSprite.tileScale.x = gridPos.zoom * 0.4;
    tilingSprite.tileScale.y = gridPos.zoom * 0.4;
  };
  eventBus.on('update', setPositions);
  setPositions();

  var world = require('./world');
  stageContainer.addChild(graphics);
  stageContainer.addChild(world.setup());

  function animate() {
    for (var i = stage.children.length; i--;) {
      if (typeof stage.children[i].update === 'function') {
        stage.children[i].update();
      }
    }
    world.update();

    requestAnimFrame( animate );

    // render the stage
    renderer.render(stage);
  }
};