rossi46 Posted December 6, 2015 Share Posted December 6, 2015 I want many games run in one page. But when i put two tags "div" in page and create two games. It run faster when has one "div". Why? I want to run phaser outside the game but not create game. How? Sorry for my bad english. Here is code of page: var count = 0; var i = true;var game = new Phaser.Game(800, 600, Phaser.WEBGL, 'content', { preload: preload, create: create, update: update });var game1 = new Phaser.Game(800, 600, Phaser.WEBGL, '', { preload: preload1, create: create1, update: update1 });//game1.paused = true; function preload1() {game1.load.image('panda2', 'img/panda.png');game1.load.image('light12', 'img/LightRotate1.png');game1.load.image('light22', 'img/LightRotate2.png');} function create1() { light12 = game1.add.sprite(game.world.centerX, game.world.centerY,'light12');light12.anchor.setTo(0.5); light22 = game1.add.sprite(game.world.centerX, game.world.centerY,'light22');light22.anchor.setTo(0.5); s_panda2 = game1.add.sprite(game.world.centerX, game.world.centerY, 'panda2');s_panda2.anchor.setTo(0.5);} function update1() {s_panda2.scale.x = 1 + Math.sin(count) * 0.01;s_panda2.scale.y = 1 + Math.cos(count) * 0.01; count += 0.1; light12.rotation += 0.02;light22.rotation += 0.02;} function preload() {game.load.image('panda', 'img/panda.png');game.load.image('light1', 'img/LightRotate1.png');game.load.image('light2', 'img/LightRotate2.png');} function create() { light1 = game.add.sprite(game.world.centerX, game.world.centerY,'light1');light1.anchor.setTo(0.5); light2 = game.add.sprite(game.world.centerX, game.world.centerY,'light2');light2.anchor.setTo(0.5); s_panda = game.add.sprite(game.world.centerX, game.world.centerY, 'panda');s_panda.anchor.setTo(0.5);} function update() {if(i) {s_panda.scale.x = 1 + Math.sin(count) * 0.01;s_panda.scale.y = 1 + Math.cos(count) * 0.01; count += 0.1; light1.rotation += 0.02;light2.rotation += 0.02;}} function test(){i = true;}function set(){i = false;} Link to comment Share on other sites More sharing options...
liakos1992 Posted December 6, 2015 Share Posted December 6, 2015 Running 2 games at the same time can destroy your GPU (i don't know if it's even possible) There is a way to change between two games. But you have to wrap each phaser game to a different GAME objectvar GAME_A = { someGameData: {}, end: function() { if (typeof GAME_A.game !== 'undefined') {GAME_A.game.destroy();} // clear all GAME_A data GAME_A.someGameData = {}; }, start: function() { GAME_A.end(); GAME_A.game = new Phaser.Game(800, 600, Phaser.AUTO, "", {preload:GAME_A.preload, create:GAME_A.create, update:GAME_A.update}); }, game: undefined, // the phaser game preload: function() { }, create: function() { }, update: function() { }}var GAME_B = { someGameData: {}, end: function() { if (typeof GAME_B.game !== 'undefined') {GAME_B.game.destroy();} // clear all GAME_B data GAME_B.someGameData = {}; }, start: function() { GAME_B.end(); GAME_B.game = new Phaser.Game(800, 600, Phaser.AUTO, "", {preload:GAME_B.preload, create:GAME_B.create, update:GAME_B.update}); }, game: undefined, // the phaser game preload: function() { }, create: function() { }, update: function() { }}// CHANGING TO GAME AGAME_B.end();GAME_A.start();///////////////////// CHANGING TO GAME BGAME_A.end();GAME_B.start();/////////////////// Link to comment Share on other sites More sharing options...
Recommended Posts