jloa

Members
  • Content Count

    20
  • Joined

  • Last visited

About jloa

  • Rank
    Member

Recent Profile Visitors

688 profile views
  1. You can write your own method with the same loop as http://docs.phaser.io/Tilemap.js.html#sunlight-1-line-378 but which will only return x/y if object's found. Incase you don't actually need to create the sprite, but rather just know the x/y
  2. Yeah, i was just about to recomend you rewrite the code http://docs.phaser.io/TilemapParser.js.html#sunlight-1-line-257
  3. Nah, i was wrong. Well, my code works as i've got one big tileset for all layers. But it won't work if you have many tilesets. In case you have many tilesets the rules is simple: tileset.firstgid + firstgid.tileProperties.id = tile.idSo to find the props you need: /** * Return tile properties or null if not props are defined for this tile * @param map:Phaser.Tilemap tilemap reference * @param tile:Phaser.Tile the tile * @return Object tile properties or null if no defined */var getTileProps(map, tile){ // grab the tile index var tileIndex = tile.index; // loop through all tilesets for(var i = 0, n = map.tilesets.length; i < n; ++i) { var tileset = map.tilesets[i]; // prop index var propIndex = tile.index - tileset.firstgid; // prop index must be >=0, so the tile might be from this set if(propIndex >= 0) { // properties found! if(tileset.tileProperties[propIndex] != undefined) { return tileset.tileProperties[propIndex]; } } } // no props found :-( return null;}
  4. Btw, there are other properties that are not copied from the json. For example Phaser.TilemapLayer is not copying opactiy and visible properties, so i had to make a dirty fix var layer = this.map.createLayer(layerName, undefined, undefined, layerGroup);// @FIX not implemented - the 'alpha' and 'visible' inheritance, nor the 'name'layer.alpha = layer.layer.alpha;layer.visible = layer.layer.visible;layer.name = layer.layer.name;Check out the source if you don't believe me http://docs.phaser.io/TilemapLayer.js.html#sunlight-1-line-1 Ps: there are tons of such weird things (and bugs! btw), i've already got a "phaser-fix.js" with tons of overrides/extends, will push it to the repo later when i got time.
  5. And i've just answerd this issue here -> http://www.html5gamedevs.com/topic/8415-tiled-tile-properties/
  6. Let me help you, i've just faced the same problem. Why are not props copied - dunno, i asked myself same question. Mb performance related? Imagine you have 100500 tiles of 2 types. Anyways, here's how you can grab the props of a tile: var map = game.add.tilemap('id-of-the-json-defined-in-the-game.load');// tile is a Phaser.Tile; i'm using x/y world coordinates to grab the tile, but you can also grab a tile by i/j indexes @see the docsvar tile = map.getTileWorldXY(x, y, undefined, undefined, 'your-layer-name-in-json');// null = not such tile under x/yif(tile != null){ // the tileset index var index = map.getTilesetIndex('your-tileset-name-in-json'); // null = no such tileset if(index != null) { var tileset = map.tilesets[index]; // finally you can grab the props of your tile - mind that Phaser.Tile.index starts with 1; however tileProperties start with 0; var tileProps = tileset.tileProperties[tile.index-1]; }}The really weird thing is why are tile's indexes and props indexes different -- a mystery
  7. Ok, so can someone of you guys that know the architecture of phaser exaplain me the workflow of the lib so that i save my tike reading all the source code? So far i thought the workflow was similar to this: - preload assets, create cache, for bitmaps create images and cache them - create and setup all managers (stage, states, physics etc) - create the renderer (a single canvas or single texture) - ready for ticks every tick: - clear the canvas/texture - call preUpdate() all stuff (cache, states, stage etc this includes physics, display objects) - call user defined update() stuff - call update on all managers (physics, display objects etc) - call postUpdate() on all managers (physics, display objects etc) - call render() on all display objects (let them modify their own bitmapdatas with filters/blend modes, transform matrixes etc) - call renderer.render() - cycle through all display objects, grab their final bitmapdata and draw all those bitmapdatas it on 1 single canvas/texture according to z-index) - call user defined render() No need to create more than 1 canvas or texture. As a result - performance depends only on code optimization and loop-length, not on rendering. Does phaser work so? I hope Richard sees this and writes back :/
  8. Ok, i've decided to make a blank project to test the lags. Just a simple box 20x20 pixels flying around. So, when i fly around it still lags. Drops fps to 54-56 on a blank project. What am i doing wrong? Btw switching to canvas doesn't help. Same drops to 54-56 fps. var ns = ns || {};var box;(function(ns){ var cursors; var worldInfo = { 'w': 1000, 'h': 800, }; var preload = function() { game.load.image('box', 'assets/i/box.png'); }; var create = function() { game.time.advancedTiming = true; game.world.setBounds(0, 0, worldInfo.w, worldInfo.h); // stage game.stage.disableVisibilityChange = true; game.stage.backgroundColor = '#ffffff'; // physics game.physics.startSystem(Phaser.Physics.P2JS); game.physics.p2.setBounds(0, 0, worldInfo.w, worldInfo.h, true, true, true, true, false); game.physics.p2.useElapsedTime = true; game.physics.p2.applyDamping = true; game.physics.p2.setWorldMaterial(game.physics.p2.createMaterial('worldMaterial'), true, true, true, true); box = game.add.sprite(200, 200, 'box', 0); game.physics.p2.enable(box); box.body.damphing box.body.mass = 1; box.body.damping = .1; box.body.angularDamping = .1; // camera game.camera.follow(box, Phaser.Camera.FOLLOW_LOCKON); // cursors cursors = game.input.keyboard.createCursorKeys(); }; var update = function() { var force = 10; if(cursors.left.isDown) { box.body.applyForce([force, 0], box.x, box.y); } else if(cursors.right.isDown) { box.body.applyForce([-force, 0], box.x, box.y); } if(cursors.up.isDown) { box.body.applyForce([0, force], box.x, box.y); } else if(cursors.down.isDown) { box.body.applyForce([0, -force], box.x, box.y); } }; var render = function() { }; game = new Phaser.Game( 1000, 800, Phaser.WEBGL, 'game', { preload: preload, create: create, update: update, render: render } );})(ns);
  9. And why does it use 8 canvas instances rather than render the whole scene on 1? O_o From my expirience it should not matter how many layers/objects/tilemaps/sprites etc (display objects) you have. The engine should combine then according to the z-index like a sadwitch and render a single birmapdata (all objects combined) on 1 canvas/texture. No matter what the case is. Doesn't it work that way in phaser? You grab all your objects which are bitmapdatas with a corresponding transform matrix (x/y/rotation/scale etc) and just paint them on a single canvas (texture). I think that's the reason why my project super lags when i use 10-layer tilemap with a lockon camera, if phaser really dupes canvas/textures. Then it's time to rewrite the renderer in that case. Some meta-code how the rendering should be done // canvas/texture// cleargfx.clear();// start renderinggfx.begin();...// render each childfor each displayOjbect{gfx.draw(child);}...// only then output a single canvas/texturegfx.end();
  10. Does the game freeze totally or temporary? Which browser are you using? If totally - check the code, 100% sure it's the source of the perma-freeze. If temporary... Check the code, but that might not be the reason. There's some weird thing or bug with ie, firefox, the game can randomly freeze for like less than 50ms and the unfreeze. Happens totally random, even on a blank project and doesn't depend on fps, fps can still be 60/60. Still investigating this...
  11. First of all here are the specs of my pc: - MS Windows 7 64-bit SP1 - IntelĀ® Core i5-4570 CPU @ 3.20GHz 4-core - 16 gb ddr3 ram @ 2300 mhz - NVIDIA GeForce GTX 660, 2 gb dd5 ram (driver version: 9.18.13.3221) - Firefox 31, latest (Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0) Here are the graphics settings in firefox (gpu acc enabled, webgl enabled, direct2D enabled etc...) { "application": { "name": "Firefox", "version": "31.0", "userAgent": "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Firefox/31.0", "supportURL": "https://support.mozilla.org/1/firefox/31.0/WINNT/en-US/" } "modifiedPreferences": { "dom.ipc.plugins.enabled.npietab2.dll": true, "dom.mozApps.used": true, "gfx.direct3d.last_used_feature_level_idx": 0, }, "graphics": { "numTotalWindows": 2, "numAcceleratedWindows": 2, "windowLayerManagerType": "Direct3D 10", "windowLayerManagerRemote": false, "adapterDescription": "NVIDIA GeForce GTX 660 ", "adapterVendorID": "0x10de", "adapterDeviceID": "0x11c0", "adapterRAM": "2048", "adapterDrivers": "nvd3dumx,nvwgf2umx,nvwgf2umx nvd3dum,nvwgf2um,nvwgf2um", "driverVersion": "9.18.13.3221", "driverDate": "12-19-2013", "adapterDescription2": "", "adapterVendorID2": "", "adapterDeviceID2": "", "adapterRAM2": "", "adapterDrivers2": "", "driverVersion2": "", "driverDate2": "", "isGPU2Active": false, "direct2DEnabled": true, "directWriteEnabled": true, "directWriteVersion": "6.2.9200.16492", "webglRenderer": "Google Inc. -- ANGLE (NVIDIA GeForce GTX 660 Direct3D9Ex vs_3_0 ps_3_0)", "info": { "AzureCanvasBackend": "direct2d", "AzureSkiaAccelerated": 0, "AzureFallbackCanvasBackend": "cairo", "AzureContentBackend": "direct2d" } }}But still, firefox lags like hell when using Phaser.WEBGL mode when using simple text/lines. Also from time to time fps just drop like 5-7 fps and then goes back even on a white blank project. Test it yourself: 1. Open official example in firefox http://examples.phaser.io/_site/view_full.html?d=games&f=tanks.js&t=tanks 2. Open the browser console (press ctrl + shift + j or go to Developer >> browser console) 3. Inject this code in the console // for fps measuringgame.time.advancedTiming = true;// override the original render() method game.state.onRenderCallback = function(){ game.debug.text('fps: '+game.time.fps, 32, 20);}4. Check the fps (in my case drops to 54-56) 5. Inject this code in the console // override the original render() method game.state.onRenderCallback = function(){ // welcome to the Laggy-Land :-) game.debug.text('fps: '+game.time.fps, 32, 20); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 40); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 60); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 80); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 100); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 120); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 140); game.debug.text('Enemies: ' + enemiesAlive + ' / ' + enemiesTotal, 32, 160)}6. Check the fps (in my case it drops to 24-26) The webGL renderer not able to render 8 texts? How? Why?! I've test three.js demos - all work perfectly on this hw setup in firefox. Also tested pixie demos - same, works perfectly 60/60 fps. Here a screenshot PS: also i've noticed that in IE and Firefox on either canvas or webgl mode sprites twitch from time to time, happens totally random - the sprite moves smooth, fps is 60 and then it just starts twitching while moving without fps drops. Chrome works perfectly of either modes, no glitches, no twitching - perfecto.
  12. jloa

    Performance

    Stumbled the same things btw. WebGL is very VERY slow in firefox. Dunno why. Especially if you render text using "game.debug.text". For example, my game with 8 debug texts get a 4/60 fps drop on webgl, when i remove the "game.debug.text" calls i get stable 45-50 fps out of 60. Btw on canvas i get 60/60 fps in firefox with and without "game.debug.text" calls.
  13. Before creating an issue on github, decided to put it here (as suggested here https://github.com/photonstorm/phaser/blob/master/CONTRIBUTING.md) Class: Phaser.Physics.P2 Method: constructor Issue: physics config's user-defined options (mpx, mpxi, pxm, pxmi) get deleted in Phaser.Physics.P2 constructor. Proof: Why: game class instance passes the physics config to Phaser.Physics instance, then the config gets passed to Phaser.Physics.P2. Within this chain no other props are created, as a result 'broadphase' prop is never present in the physics config and always created by the p2 class. So, when a new p2 instace is created, the config with your custom mpx, mpxi, pxm, pxmi props gets replaced with a new config of { gravity, broadphase } only. As a result p2 uses default mpx, mpxi, pxm, pxmi methods (so they don't get overriden) How-to-fix: switch from config replacement to property adding. Current code: Phaser.Physics.P2 = function (game, config) {/** * @property {Phaser.Game} game - Local reference to game. */this.game = game;// @note// what if i already defined 'gravity' and 'broadphase' is not defined (btw it's never defined until this point)// my gravity prop will be also overridenif (typeof config === 'undefined' || !config.hasOwnProperty('gravity') || !config.hasOwnProperty('broadphase')){ config = { gravity: [0, 0], broadphase: new p2.SAPBroadphase() };}The fix: Phaser.Physics.P2 = function (game, config) {/** * @property {Phaser.Game} game - Local reference to game. */this.game = game;// config exists? if not - create oneif (typeof config === 'undefined'){ config = {};}// we got gravity? if not - define [0,0]if (!config.hasOwnProperty('gravity')){ config.gravity = [0, 0];}// we got broadphase? if not - create a new instanceif (!config.hasOwnProperty('broadphase')){ config.broadphase = new p2.SAPBroadphase();}// ... now mpx, mpxi, pxm, pxmi props will override the default methods properly// Pixel to meter function overridesif (config.hasOwnProperty('mpx') && config.hasOwnProperty('pxm') && config.hasOwnProperty('mpxi') && config.hasOwnProperty('pxmi')){ this.mpx = config.mpx; this.mpxi = config.mpxi; this.pxm = config.pxm; this.pxmi = config.pxmi;}
  14. Ye, that's what i thought until i dived into the source of phaser. For example the p2.Body.velocity property. They made a proxy point class in order to manage the metrics convertation which is nice, but it works only one-way. See the source http://docs.phaser.io/InversePointProxy.js.html#sunlight-1-line-25 So basically as you work with pixels in phaser, when you set velocity.x = some_value it's converted to meters inverted (why did they invert the values??), but if you get the velocity.x it won't be converted back from inverted meters to pixels. I had to override this class' getters, to make it work properly. // @FIX convert back to pixelsget: function (){ return this.world.mpx(this.destination[0]);},Also the forces are applied inverted. Which is also weird. If i apply a [10, 0] force to a object i expect the object to move to right, but not in phaser :-) http://docs.phaser.io/Body.js__.html#sunlight-1-line-419 I don't understand why they used pxmi() method to invert the values. Why? It's obvious that the force would move the object in the same direction, not the opposite. I've already overriden this method too with pxm() - now works properly. Lots of work to do with overriding still to go... :-( UPD: btw my game physics are finally working after my InversePointProxy getters patch. Spent 3 days trying to figure out what was wrong until i decided to look at the phaser's source.
  15. Ye, thanks i know how to make globalToLocal/localToGlobal (btw parent might be not the top lvl) But, still what do toWorldFrame / toLocalFrame methods do?