Scalemail Ted

  • Content Count

  • Joined

  • Last visited

  1. Thanks wkd-aine, this is a similar solution to what I had done, but yours is more elegant by just overriding the createFromObjects method. I had originally created a helper function within the scene to add the properties into my objects after they had been grouped, so i was iterating over all the elements twice >_<: addPropertiesToObject( gid, objGroup ) { var props ='objects', (obj) => {if (obj.gid === gid) return obj} ) for (var index in objGroup) { Object.assign( objGroup[index], props[index].properties ); } }
  2. I found a Phaser 3 lab example using createFromObjects:\game objects\tilemap\static\create from objects.js However, it does not cover my use case as this example's Object Layer's properties object strictly contains an 'alpha' field, which is one of the keys that is explicitly checked by the BuildGameObject method, as stated in my previous post. (Link to example's JSON, where the only property defined in object layer is alpha) Is there example code for the Phaser 3 createFromObjects method where the properties object includes some non-graphics biased data, such as some event-triggering property. Or is this not an intended use case for the Phaser 3 createFromObject method? In Phaser 2, it appears that Sprites would inherit all of the 'properties' defined within the Object Layer, because it does the following for-loop (link to Phaser 2 source code) : Is there a reason why it appears that Phaser 3's createFromObject seems to omit this? If so, is there a known alternative to produce a similar result as Phaser 2's createFromObject method?
  3. So, I've delved deeper into this rabbit hole, tracing into the source code for the methods responsible for constructing the Sprite objects. As can be seen in the previous post, on line 71803 in createFromObjects each Sprite object is constructed by invoking the factory method this.scene.make.sprite(config) where the config object that is passed contains the following attributes: {key, frame, key_id, x , y}. Note that the key_id is inserted into the config object via the Extend( {}, config, ), where key_id is defined within the properties field of obj. So tracing back into the make.sprite method using a config object as an argument (link to source) : There is an invocation to the method GetAdvancedValue passing 'key', and 'frame' to get the corresponding values from the config object and then a new Sprite object is instantiated using as the parameter list: scene object, x, y, key, and frame. Then a call to BuildGameObject (link to code) is made, where the config object is passed to it. [Note: This method is too large to directly post so I've linked it]. It appears the keys that BuildGameObject explicitly seeks to define within the created gameObject are: x, y, depth, flipX, flipY, scale, scrollFactor, rotation, angle, alpha, origin, scalemode, blendmode, visible, add. So as best as I can tell the factory method used to create Sprite objects from a configuration object ignores all other fields besides the ones explicitly listed above, thus my key_id attribute is never added into the Sprite object. Is this a correct understanding of the sequence of calls? If so, is there a way to have additional attributes in the config object to be added to the Sprite object? Or more precisely, how can I get the key_id (within properties) to get added into the resultant Sprite object when importing from a Object Layer (via Tiled JSON)?
  4. So according to the documentation createFromObjects is suppose to copy over the 'properties' attributes from the map data So I dug into the source code for createFromObjects and inserted some logging to see the config data before making a sprite and after. You can see in my screenshot, that I added some console.logs on lines 71802 and 71804 in phaser.js, where respecitvely I console.log(config) and then console.log(sprite) The resulting output in my console for the config object is shown below. You can clearly see that the 'properties' attribute of key_id is there. But when I display the resulting Sprite object constructed from that config object, it does not have either a key_id attribute or a properties field Am I missing something simple? Shouldn't the key_id be an attribute in this new Sprite object?
  5. I am using createFromObjects (Link to API) to create a collection of Sprites from the object layer imported from a Tiled JSON file. I have successfully created the collection of sprites, however, I seem to be missing some critical data from these newly created Sprite objects. The original JSON tile data has a 'properties' field containing a unique key_id for each particular 'key' tile which appears to not copy over with this method invocation. Is there a way to get these 'properties' values from the object layer into each of the new Sprite objects?
  6. I found a solution that works, but it is NOT the most elegant of solutions. Here is my current level parsing function, which works for half collisions on floor-spikes and ceiling-spikes: setTile(x, y, tileID){ if (tileID == "#" ){ this.platforms.create(x*32 + 16, y*32 + 16, 'brick'); } else if (tileID == "@" ) { this.player = this.physics.add.sprite(x*32+16, y*32+2, 'hero'); this.player.setCollideWorldBounds(true); } else if (tileID == "A" ){ let spike = this.hazards.create(x*32+16, y*32+16, 'spike-floor'); spike.body.height = 16; spike.body.customSeparateY = true; spike.body.y += 16; } else if (tileID == "V" ) { let spike = this.hazards.create(x*32+16, y*32+16, 'spike-ceiling'); spike.body.height = 16; } } Is there a cleaner way of achieving/expressing the same functionality?
  7. I'm attempting to learn Phaser 3 by building a very simple Platformer game. The game is tile based, such that all of my tiles are 32 pixel by 32 pixel. The initial state of my scene is loaded from a 2d array, that I parse into the level during the create phase. My issue is that my hazard tiles, (floor spikes and ceiling spikes) should have collisions only on the bottom half or top half of the sprite. Is there as way to modify the default hitbox of a sprite and redefine it to only be half the height from either the bottom-to-center or top-to-center?
  8. I know this question is from February, but I just encountered the same issue when trying to type out the tutorial on my own, and the solution is pretty straight forward, so I wanted to share since this post pops up first on a Google search. If you encounter this error. Ensure that you tell load to create a spritesheet and not an image: this.load.spritesheet('dude', 'assets/dude.png', {frameWidth: 32, frameHeight: 48}); And NOT: this.load.image('dude', 'assets/dude.png', {frameWidth: 32, frameHeight: 48});