Vexen Crabtree

  • Content count

  • Joined

  • Last visited

  1. It's this line that I worry about the most (using the current live version): var nextX = this.x + direccion*(Math.abs(this.width/2)+1); Also, Math.abs() doesn't make sense, unless your sprites have negative width? Is it supposed to be Math.floor()? I would setup a "nextGridY" set of variables. For nextGridX it would be something like: var nextGridX = Math.floor(this.x/32) + direccion; And to make it easier, a setOrigin of (0,1) might help (i.e., so the sprites are bottom-aligned).
  2. I can't see what's wrong with the code excerpt, but a simple way around the problem would be to use invisible immovable tiles at the end of platforms (one space off of their edge at the walkable height), and set a horizontal bounce property of the moving sprite. So when the sprite hits the invisible tile, it bounces off in the opposite direction.
  3. Vexen Crabtree

    Phaser 3 FAQs

    This a really great set of resources, I've really been wanting to read about scenes in particular. I've turned the "Control Panel / Status Panel" in my newbie game into its own scene with relative ease.
  4. Vexen Crabtree

    How to find out that a file failed to load

    Got it! To catch when a JSON file doesn't load (presumably this will work for all filetypes): function loadLevel(pLevelID){ if(config.t.cache.json.has(pLevelID+'levelData')){ //File already loaded into cache gl_3_loadlLevel_onJSON(); }else{ config.t.load.once('complete', function (){gl_3_loadlLevel_onJSON();}, this); config.t.load.json(pLevelID+'levelData', "maps/"+pLevelID+".json").on('loaderror', gl_3_loadFileFail, this); config.t.load.start(); } } function gl_3_loadFileFail(){ loadLevel('home'); }; So, the "loaderror" event works for .on but it is an all-lowercase name (the documentation has "loadError" with a capital E. Although doing .once("loaderror",...) didn't work (I tried previously). Here's what could be improved in the documentation (for those who are listening, and have time...) Make it so that you can find "this.load.json" without having to search through (in detail) lots of documentation files, by adding "Phaser.load" to the menu, even if it merely redirects the browser to . On that file, for the different occasions where it says "Add a listener for a given event" (for example in the entries for .on and .once), have a place where it lists all the possible valid event names (with correct capitalisation). In the "Events" section of that page, where it lists events like "loadErrorEvent", state what methods will work to call those events. For example, to call "completeEvent" you can use "this.load.once('complete')" (or other methods, probably), but for the "loadError" event list only the .on('loaderror',...) (plus whatever other methods work).
  5. Vexen Crabtree

    How to find out that a file failed to load

    In one of the examples I saw a different technique for getting hooks to the file load events; events/file complete event.js had: this.load.image('taikodrummaster', 'assets/pics/taikodrummaster.jpg').on('filecomplete', addImage, this); So I've tried: config.t.load.json(pLevelID+'levelData', "maps/"+pLevelID+".json").on('onError', function(){alert("hi")}, this); config.t.load.start(); But the alert doesn't show - I've tried event names of "loadError", "onError"
  6. Vexen Crabtree

    How to find out that a file failed to load

    I've tried "onLoad" and other possible names for the "failed to load file" event, but still no luck. The documentation says that errorLoad "is fired when the a file errors during load"; maybe because it says during load, that this event only fires once a load has started, and therefore, won't be invoked in the case of a 404, where the file never starts? (Although a GET HTTP TCP session clearly starts, because the webserver returns the 404 status code to the browser, so I think it is unlikely that the errorLoad wouldn't fire).
  7. Vexen Crabtree

    How to find out that a file failed to load

    I'm using this.load.JSON and then trying to detect if the file fails to load. If it is a "404" then I want to redirect the user to the loading page and log an error (etc). Whatever I find for this.load.JSON should probably also work with whatever filetype it is that you're using. There isn't a namespace or class in the documentation that directly matches this.load.JSON or Phaser.load.JSON or Phaser.Load so this is where I've checked: Namespace: Phaser.Loader is (I think) information about internal file handling or something similar. Namespace: Phaser.Loader.FileTypes has entry for JSONFileConfig but nothing on .load for types of files. I think this and the previous one must both be used by this.load.JSON. Class: Phaser.Loader.File says for its load() method that "You shouldn't normally call this method directly, it's meant to be invoked by the Loader" so this is probably also used by this.load.JSON. It does also have an "onError" method. Class: Phaser.Loader.FileTypes.JSONFile sounds like the perfect place to look; but it's class constructor doesn't match. It says "new JSONFile(loader, key [, url] [, xhrSettings] [, dataKey])" whereas I'm looking for .load(KEY, URL), and, it's .load() method also says "You shouldn't normally call this method directly, it's meant to be invoked by the Loader". Class: Phaser.Loader.LoaderPlugin sounded like a loader for plugins (i.e., for adding plugins to Phaser3). And it was last in the Phaser.Loader classes, so I checked it last. But its opening description talks about using this.load (yay). It doesn't have a method called .load() unfortunately, but, it does have one called .json() which matches the code from the Examples which I used to load .JSON files: So, that last one was the correct place to look. Class: Phaser.Loader.LoaderPlugin.json(key [, url] [, dataKey] [, xhrSettings]) contains the documention for this.load.JSON. I was hoping there would be parameters along the lines of "errorCallback" which would be passed the HTML status code (i.e., HTTP 404 or HTTP 500). That class also has events like "completeEvent" and "loadErrorEvent". I already use the "completeEvent" config.t.load.once('complete', function (){gl_3_loadlLevel_onJSON();}, this); config.t.load.json(pLevel+'levelData', "maps/"+pLevel+".json"); config.t.load.start(); In the documentation, it looks like the "completeEvent" matches the 'complete', and therefore, that "loadErrorEvent" could be called 'loadError'. So I tried adding this.load.once('loadError'), but it doesn't fire when the wanted file causes an error (i.e. 404). function loadLevel(pLevel){ if(config.t.cache.json.has(pLevel+'levelData')){ //File already loaded into cache gl_3_loadlLevel_onJSON(); }else{ config.t.load.once('complete', function (){gl_3_loadlLevel_onJSON();}, this); config.t.load.once('loadError', function (){gl_3_loadFileFail(); }, this); config.t.load.json(pLevel+'levelData', "maps/"+pLevel+".json"); config.t.load.start(); }; }; function gl_3_loadFileFail(pFile){ alert("uh oh"); }; function gl_3_loadlLevel_onJSON(){ //Once a new JSON file is successfully loaded, this function is called }; I'm still fairly sure that the answer is in Class: Phaser.Loader.LoaderPlugin somewhere ( ), it has the code for the .once() method, which says "Add a one-time listener for a given event" - sounds perfect, if you want to catch a possible onError type event for a file load. But, it doesn't list what the names of valid events are. "complete" works but "loadError", "loaderror", "loadErrorEvent" and "loaderrorevent" don't work. I'll let you know if I get it working! I wish "Phaser.Load" appeared in the documentation Classes menu, it would have made this search somewhat shorter!
  8. Vexen Crabtree

    How to find out that a file failed to load

    I'm finding out how to do this at the moment, I'll post here if I get an answer.
  9. Vexen Crabtree

    failed to load image

    What's the relative paths of the file that contains your code, and the asset you're loading?
  10. Vexen Crabtree

    Finding this.physics.add.collider in the documentation

    Ah, so on the documentation that's in Classes > Phaser.Physics.Arcade.ArcadePhysics , item "add :Phaser.Physics.Arcade.Factory". It's obvious (ish) in retrospect, but difficult to get there from scratch! So it must be the same with all the physics modules (just thinking out loud for the benefit of others); the physics.add methods are in places like Physics.Impact.ImpactPhysics, and Physics.Matter.MatterPhysics . Thanks for the quick and terse reply!
  11. When we want to go find the documentation for Phaser3 classes, how do we know where to look? For example: this.physics.add.collider(levelData.dynDoors, glPlayer, door_enter); A namespace? You might think that the "Phaser.Physics" namespace was a good place to look (once selecting which graphics engine you're using - Arcade in my case), but, there's no method called "Add" there. [http://localhost/docs/Phaser.Physics.Arcade.html]. A class? So the next thing to try might be to find the class for Phaser.Physics (doesn't exist), so maybe it is Phaser.Physics.Arcade.something . I could guess that it is Phaser.Physics.Arcade.Collider (possibly add.collider is documented in Collider.Add, or something...). There isn't a ".add" in there, but the documentation page does open with a "new Collider(....)" description. So perhaps physics.add.collider invokes a new collider - makes sense! But, the description for new Collider doesn't match the code. Code: levelData.layer = levelData.tilemap.createDynamicLayer(0, levelData.tileset, 0, 0); this.physics.add.collider(glPlayer.body, levelData.layer); this.physics.add.collider(dynCreatures, levelData.layer); this.physics.add.collider(levelData.dynDoors, levelData.layer); this.physics.add.collider(dynBoulders, levelData.layer); As in, add.collider accepts two parameters, but the "new Colldier" description has a list of 7 mandatory parameters. From http://localhost/docs/Phaser.Physics.Arcade.Collider.html. Phaser.Physics.Arcade.Collider [description] new Collider(world, overlapOnly, object1, object2, collideCallback, processCallback, callbackContext) I've tried adding colliderCallback and overlapOnly parameters, but can't get them to work - probably because I haven't found the correct bit of documentation for physics.add.collider. This approach (of looking in Namespaces, Classes, Events, for documentation to match Examples and existing code is very often long-winded and I think my basic method must be wrong. I know the documentation is behind the development, but any ideas?
  12. Vexen Crabtree

    Returning all tiles of a specific type

    .filterTiles doesn't have a "by index type" filter option, so here's the code I've ended up with: levelData.dirtStartQ=0; levelData.tilemap.forEachTile(function(pTile){ if(pTile.index==11){ levelData.dirtStartQ++; pTile.setAlpha(0.7) }; });
  13. Vexen Crabtree

    Returning all tiles of a specific type

    filterTiles(callback [, context] [, tileX] [, tileY] [, width] [, height] [, filteringOptions]) appears to be the solution (testing it now), if so I'll delete this thread...
  14. Vexen Crabtree

    Returning all tiles of a specific type

    I want to adjust the alpha of all tiles of a particular type, but I don't know an elegant way of doing it... I could iterate through all tiles, and find them one by one. Is there a cleverer way? Something like a "get_tilesByType" function, used like this: levelData.tilemap.get_tilesByType(11).setAlpha(0.7); (or iterating through each returned object and running .setAlpha). As the player runs around, they clean up 'dirt' (tile index = 11 from the tilemap). How do I count how many dirts remain? It is likely a similar solution to the one above; var dirt_remaining = levelData.tilemap.get_tilesByType(11).length; If you're interested, this is how I'm cleaning dirt tiles: levelData.tilemap.setTileIndexCallback(11,cleanDirt,this); function cleanDirt(pPlayer,pTile) //Has to accept pPlayer because this is invoked by a game collide callback levelData.tilemap.fill(-1,pTile.x,pTile.y,1,1); dirtCleanedQ+=1; txtComplete.setText("Cleanliness:\n " + Math.floor(100*dirtCleanedQ/dirtStartQ) + "%"); };
  15. Vexen Crabtree

    Questions about Phaser 3?

    I started with Phaser3 just a week ago (hello everyone, maybe we should have an 'Introductions' forum!); this is my first go at making any game using a plugin or engine. Although much of the terminology is new to me, and the documentation is bare-bones, I'm still managing to get things done.