• Content Count

  • Joined

  • Last visited

About RedPanduzer

  • Rank

Recent Profile Visitors

611 profile views
  1. Thanks. I was aware of CE-edition but just took the newest version from Phaser download page. As a side note it might make things less confusing if there would be a link to CE-edition on that download page too. For me, it doesn't really matter as I'm running custom version anyway.
  2. Calling removeChirldren on sprite causes reference error because begin is not defined. Function gets beginIndex as parameter but never defines begin variable. Fix is as simple as changing begin to beginIndex. There is open issue on this. My Phaser version is 2.6.2
  3. Thanks for the answers. I tried both solutions. With lowering till flicker starts, objects where still way too high (no idea why). I also tried to smaller body sizes but even in very small size, objects flickered and field body couldn't be made smaller. I once tried simple sorting too, but that broke thing rather badly. However, I came up with the solution where field isn't isoSprite at all. That was my original idea but I failed to make work back then. Now it seems I'm getting somewhere and that way there is no flickering at all.
  4. I'm trying to create simple isometric game using @lewster32's iso plugin, where player needs to transport his/her hero from point A to point B in simple city. Nothing special there. However, some buildings start flickering and I can't figure how to stop it. Only solution I came up with, is that I place them in air but that's not very good because small character can go below them. It seem that the issue is with body.immovable = true and body.moves = false commands. If I give those for the field itself, flickering starts. My code: var kentta; var house; var cube; var game = new Phaser.Game(1280, 800, Phaser.AUTO, 'test', null, true, false); var BasicGame = function (game) { }; BasicGame.Boot = function (game) { }; var isoGroup, player; BasicGame.Boot.prototype = { preload: function () { game.load.image('cube', 'police_dep.png'); game.load.image('kentta', 'kentta1.png'); game.load.image('house1', 'house1.png'); game.load.image('house2', 'house2.png'); game.load.image('house3', 'house3.png'); game.load.image('house5', 'house5.png'); game.load.image('house6', 'house6.png'); game.load.image('park', 'park.png'); game.load.image('factory', 'factory.png'); game.time.advancedTiming = true; // Add and enable the plug-in. game.plugins.add(new Phaser.Plugin.Isometric(game)); // Start the IsoArcade physics system. game.physics.startSystem(Phaser.Plugin.Isometric.ISOARCADE); // This is used to set a game canvas-based offset for the 0, 0, 0 isometric coordinate - by default // this point would be at screen coordinates 0, 0 (top left) which is usually undesirable. game.iso.anchor.setTo(0.5, 0.5); }, create: function () { // Create a group for our tiles, so we can use Group.sort isoGroup =; isoGroup.enableBody = true; isoGroup.physicsBodyType = Phaser.Plugin.Isometric.ISOARCADE; // Set the global gravity for IsoArcade. game.physics.isoArcade.gravity.setTo(0, 0, -500); kentta = game.add.isoSprite(200,0,20,'kentta',0,isoGroup); kentta.anchor.setTo(0.5,0); game.physics.isoArcade.enable(kentta); kentta.body.immovable = true; kentta.moves = false; house = game.add.isoSprite(410,70,0,'house1',0,isoGroup); house.anchor.setTo(0.5); house2 = game.add.isoSprite(440,180,100,'house2',0,isoGroup); house2.anchor.setTo(0.5); house3 = game.add.isoSprite(440,250,100,'house2',0,isoGroup); house3.anchor.setTo(0.5); house4 = game.add.isoSprite(340,275,100,'house3',0,isoGroup); house4.anchor.setTo(0.5); house5 = game.add.isoSprite(500,275,100,'house5',0,isoGroup); house5.anchor.setTo(0.5); house6 = game.add.isoSprite(475,90,100,'house6',0,isoGroup); house6.anchor.setTo(0.5); park = game.add.isoSprite(330,140,80,'park',0,isoGroup); park.anchor.setTo(0.5); factory = game.add.isoSprite(240,270,80,'factory',0,isoGroup); factory.anchor.setTo(0.5); // Create another cube as our 'player', and set it up just like the cubes above. player = game.add.isoSprite(200, 0, 100, 'cube', 0, isoGroup); player.tint = 0x86bfda; player.anchor.set(0.5); game.physics.isoArcade.enable(house); game.physics.isoArcade.enable(house2); game.physics.isoArcade.enable(house3); game.physics.isoArcade.enable(house4); game.physics.isoArcade.enable(house5); game.physics.isoArcade.enable(house6); game.physics.isoArcade.enable(park); game.physics.isoArcade.enable(player); park.body.moves = false; park.body.immovable = true; factory.body.moves = false; factory.body.immovable = true; park.scale.setTo((game.width/kentta.width)*0.5); /*kentta.body.setSize(kentta.body.widthX*1.5,kentta.body.widthY,kentta.body.height*0.5);*/ player.body.collideWorldBounds = true; kentta.body.collideWorldBounds = true; house.body.collideWorldBounds = true; house2.body.collideWorldBounds = true; kentta.scale.setTo((game.width/kentta.width)*0.5); house.scale.setTo((game.width/kentta.width)*0.15); house2.scale.setTo((game.width/kentta.width)*0.15); house3.scale.setTo((game.width/kentta.width)*0.15); house4.scale.setTo((game.width/kentta.width)*0.15); house5.scale.setTo((game.width/kentta.width)*0.15); house6.scale.setTo((game.width/kentta.width)*0.15); factory.scale.setTo((game.width/kentta.width)*0.15); // Set up our controls. this.cursors = game.input.keyboard.createCursorKeys();[ Phaser.Keyboard.LEFT, Phaser.Keyboard.RIGHT, Phaser.Keyboard.UP, Phaser.Keyboard.DOWN, Phaser.Keyboard.SPACEBAR ]); var space = game.input.keyboard.addKey(Phaser.Keyboard.SPACEBAR); space.onDown.add(function () { player.body.velocity.z = 300; }, this); game.iso.projectionAngle = 0.575; //init once after endering is done setTimeout(function(){ /*kentta.body.setSize(1400,1400,60); kentta.pivot.y = -150;*/ house2.body.moves = false; house2.body.immovable = true; house3.body.moves = false; house3.body.immovable = true; house4.body.moves = false; house4.body.immovable = true; house5.body.moves = false; house5.body.immovable = true; house6.body.moves = false; house6.body.immovable = true; /* park.body.moves = false; park.body.immovable = true; house.body.moves = false; house.body.immovable = true;*/ house4.body.setSize(house4.body.widthX/0.3,house4.body.widthY/0.3*1.25,house4.body.height/0.3,0,-10); house5.body.setSize(house5.body.widthX/0.3,house5.body.widthY/0.3*1.25,house5.body.height/0.3,-5,-10); park.body.setSize(park.body.widthX/0.3*1.2,park.body.widthY/0.3*1.5,park.body.height/0.3*1.5,-15,-27); },1000); }, update: function () { // Move the player at this speed. var speed = 100; if (this.cursors.up.isDown) { player.body.velocity.y = -speed; } else if (this.cursors.down.isDown) { player.body.velocity.y = speed; } else { player.body.velocity.y = 0; } if (this.cursors.left.isDown) { player.body.velocity.x = -speed; } else if (this.cursors.right.isDown) { player.body.velocity.x = speed; } else { player.body.velocity.x = 0; } // Our collision and sorting code again. game.physics.isoArcade.collide(isoGroup); game.iso.topologicalSort(isoGroup); }, render: function () { game.debug.text("Move with cursors, jump with space!", 2, 36, "#ffffff"); game.debug.text(game.time.fps || '--', 2, 14, "#a7aebe"); isoGroup.forEach(function (tile) { game.debug.body(tile, 'rgba(189, 221, 235, 0.6)', false); }); } }; game.state.add('Boot', BasicGame.Boot); game.state.start('Boot'); If you're wondering why there is a stupid timeout function, that's because all buildings flickered if those where defined in create function. I have no idea why. kentta variable is the field. Here is the picture of my game, body of field is rather off, I know, I know.
  5. I tried to play around with some complex polygons and run into some issues. I first fooled with code&web physics editor and that work like supposed. Then, i took a look on JSON format and tried create similar one by hand. After some trial and error i got it right. It collided properly with world borders and body debug looked right. However, objects didn't collide properly with other objects and now I'm wondering why.. Also, one weird error said something like "Convex polys must be in conter-clockwise order" So can anyone open this mystery, how does convex polygons collision work behind the scenes? I also noticed that shapes were divided into multiple smaller shapes in JSON. Is this simply to prettify JSON or is there actually a reason behind this?
  6. I suggest you start reading Phaser API. There you will find good documentation for Phaser that will help you with this kind of issues. If you take a closer look for that last parameter you will notice that it's a fixed time to dictate time it will take for object to arrive at target. So, if you set this for, let's say 500ms (0.5s) and your cursor is 400 pixels away from the gun, object will travel that 400 pixels in 500ms. Now if your cursor is 10pixel away, it will still take 500ms to travel that short distance of 10px and thats why it looks like "slowmotion".
  7. Sounds very familiar. In our project that had three tracks for menus and one+sound effects for the actual game, memory usage rocketed to 1200mb in menus and in game it dropped to 700-800mb. Then when returning from game to menu, garbace collector wasn't fast enough to clear memory although cache was indeed cleared. This caused game to use something like 700mb+1200mb of memory effectively crashing any browser. In chrome it just trew oh snap and on firefox caused decoding error. Other issues with web audio were very long loading times, random decoding errors, horrible performance, memory leaks and so on. Like with you, cache was cleared between states, both maually and with state.start(X,true,true). I'm sorry that I can't really help you with this as in the end we scraped both web audio and phaser sound system and switched to use vanilla JS new Audio() method. This actually removed whole bunch of issues in the project, including abyssal memory usage. EDIT: there is also option in Phaser sound manager to use audio tag which might fix some of your issues. I haven't personally tested it but I sort of guess that it still uses same methods and properties as with web audio and therefore saving the effort of rewriting your code f you wan't to try it out.
  8. Thanks for great post. I modified it a bit so that player hit detection can use the same functions and then changed AI functions so that now they are defined only once too. This is what I have now: var eachEnemyAliveFn;var commanderAI;var hunterAI;var destroyerAI;var boundsBullet;if (this.frameSkip == 0) {eachEnemyAliveFn = function(){};commanderAI = function(){};hunterAI = function(){};destroyerAI = function(){};this.frameSkip = 1;} else {this.frameSkip = 2;var enm;var eachBulletAliveFn = function( {boundsBullet =;self.bulletArray =, [enm]);if (self.bulletArray.length != 0 && self.timers[4] == 1) {hitDetector(b, enm, self.enemyAmount, self.lap, enm.getChildAt(0));} else if(self.bulletArray.length != 0 && self.timers[4] == 2){//jos pelaajaan osumista tutkitaanhitDetector(b, enm, null, self.lap, self.HPbar);}};eachEnemyAliveFn = function(en) {enm = en;if(self.timers[4] == 1){self.bullets.forEachAlive(eachBulletAliveFn);} else {self.enemyBullets.forEachAlive(eachBulletAliveFn);}};destroyerAI = function(enemy){eachEnemyAliveFn(enemy);//rest of the AI logic};hunterAI = function(enemy) {eachEnemyAliveFn(enemy);//rest of AI logic};commanderAI = function(enemy) {eachEnemyAliveFn(enemy);//rest of AI logic};}if(this.frameSkip == 2) {// Asteroidin jahtaajan tekoälythis.enemy1.forEachAlive(destroyerAI, this);this.enemy2.forEachAlive(hunterAI, this);this.enemy3.forEachAlive(commanderAI,this);this.frameSkip = 0;}self.timers[4]++;//checking enemy bulletsif(!this.ship.dying) {eachEnemyAliveFn(this.ship);}eachBulletAliveFn = null;eachEnemyAliveFn = null;self.timers[4] = 1;I can't tell exact effects of this as I didn't do performance tests between this and previous way. However, after all these changes it seems that GC can now clean variables way more efficiently and the game is even playable now I would still like to know if anyone has used precached functions with phaser statemanager? It seems like a promising idea.
  9. One of the problems with this issue has been that there hasn't been a clear reason why objects are getting created as almost all objects are created before starting an actual game. However, there has been a few things that are now fixed. Most important one seemed to be that one the enemies made use of graphics and LineTo method to simulate laser. Though laser got cleared every time new line was drawn, apparently lines and all objects that had something to do with them were kept in memory. This in long run caused rapid drop in fps after certain amount of time had passed. This of course wasn't the only problem is only started to cause issues after enoung lines were drawn. One weird thing was usage of getFirstExists(false) with bullet pool. As bullets are killed when out of bounds instead of destroyed, it made more sense to use getFirstDead(). I don't know if this had any effect on performance though. Also, I tried to make sure that all variables that are no more used are set to be null. Next I will move bullet hit testing inside enemy AI so it won't first go through all enemies and every bullet just go through all enemies to apply AI later. Currently big chunks of code are commented isolate problematic areas.
  10. I forced CANVAS a while ago when trying to improve performance on FF. That worked a bit but it's now really bad again. Performance is better on chrome (both canvas and webGL) but still not exactly what it should be. I fixed all implicitly declared variables, removed some duplicate declarations and commented out all unused test variables. Also tried reducing AI runs but run into some issues. I'm going to try given ideas tomorrow and report back then. Thank for replies.
  11. Thanks for reply. From richs post ( I understood that having both should at least to some extend work fine. Update loop really is big indeed. About 100 lines of that is actually about rotating ship correctly (and that's why I mentioned it in original post). For other parts, I really don't know how it could be made smaller AND keep all features in. Next, I'm probably going to limit how often AI function run and see if that has any effect. Btw, average run-time of update-loop per frame is about 2-0.5ms
  12. We are making a space shooter that should work on desktop browsers. However, this project has now came to face some serious performance issues that shouldn't exist. Game isn't exatly the smallest one but not that large either and yet fps can drop to 20-30fps which really makes our game sort of unplayable. After debugging and performance testing, it seems that there are some issues with memory and GC. Firefox waterfall chart, red ones are all GC And this one is from Chrome, white pie is idling and yellow scripting After reading some performance tips, a few things has come to my mind. 1. precached functions. Apparently prototypng is not exactly the fastest way of doing things. However, as we are using Phaser state manager all of our code makes use of prototyping. Can precache functions be used with state manager and if so how? (whole usage of precached functions was a bit over my head). 2. Bullet collision As we are using P2 physics for all enemies and payer but wanted to have arcade physics for bullets because it makes coding easier and we thought it would be ver heavy to have every bullet using P2 for no reason. Problem however, was how to test arcade bullet collision with P2 body. To overcome this I used P2 hitTest to test if bullet (for every bullet alive and for all targets) is over body. It worked fine but I heard creating arrays can be memory hog. Is this a totally broken way? for (var iter = 0; iter < 3; iter++) {this.enemies.getChildAt(this.lap-1).getChildAt(iter).forEachAlive(function (en) {bullets.forEachAlive(function ( {boundsBullet =;this.bulletArray =, [en]);if (this.bulletArray.length != 0) {hitDetector(b, en, self.enemyAmount, self.lap,en.getChildAt(0));}});});}3. Local vs this There are not that many globals in our game but even more this. defined variables. We use this when we need some value to be kept between update loops. Then there are local variables in update loop that are defined in every time loop runs. From what I have undestood all locals are freed for GC at the end of the loop where this variables of course are not. So, is it bad or good thing to give something to be freed for GC after every update loop or is it this. defined variables that could be reserving so much memory that GC is in trouble? 4. Tween performance How heavy tweens are? We have made a lot of our animations with tweens and I started to wonder if that could cause some issues too. Here's a link for git repo if you want take a look on code. All commenting is finnish though.. And here is a current live version I'm also very aware that current ship controlling is horribly ineffective, might just drop that totally out in future..