Skip to content

Commit 835df12

Browse files
committed
Notes about failed attempt to hack in the new layers approach quickly (proof of concept). The class relationship is more complex than it first appears and there are some odd connections and label namings which make it hard to manipulate quickly.
1 parent 6848c90 commit 835df12

1 file changed

Lines changed: 15 additions & 7 deletions

File tree

docs/_phaser_tilemap_GL_progress.txt

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,31 +114,39 @@ To test the demos, we currently need to set drawing mode to Phaser.WEBGL (in the
114114
map.addTilesetImage('CybernoidMap3BG_bank.png', 'tiles');
115115
layer = map.createLayer(0, undefined, undefined, undefined, true); <-- true specifies to use the new PIXI tilemap system
116116

117-
TODO: bug - in the sci-fly demo there is a new problem with collisions when the map has scrolled, I'm guessing this is some sort of scroll offset conflict between the display and the collision system.
117+
bug - in the sci-fly demo there is a new problem with collisions when the map has scrolled, I'm guessing this is some sort of scroll offset conflict between the display and the collision system.
118118

119119
Testing the system on tilemaps with borders and tiles with margins ("fill-tiles" example)... it works! This vindicates the change of approach because that was going to be a real pain to support if I had to recreate all the stuff that Phaser already handles out of the box!
120120

121121
Removed requirement for pixiTest parameter in createLayer by using renderType instead. I don't need to use WEBGL because it's currently hard-wired in Phaser.Game constructor code (which I had forgotten about) so all examples running locally will be using the new renderer.
122122

123-
TODO: another bug - when scrolling not only are the collisions off, the redrawing tile area gets smaller as we move away from the map origin. This could be linked to the collisions via the scroll offsets being wrong, however the area of map which is drawn appears to be in the correct place... are there two separate scroll offsets in this system? There are some calculations for start/end of drawing region, might be a good place to start looking.
123+
another bug - when scrolling not only are the collisions off, the redrawing tile area gets smaller as we move away from the map origin. This could be linked to the collisions via the scroll offsets being wrong, however the area of map which is drawn appears to be in the correct place... are there two separate scroll offsets in this system? There are some calculations for start/end of drawing region, might be a good place to start looking.
124124

125-
TODO: need to make the PIXI.Tilemap access multiple source textures and use tile width and height from the batch buffer data in order to reinstate the Phaser multiple tilesets per map capabilities.
125+
I need to make the PIXI.Tilemap access multiple source textures and use tile width and height from the batch buffer data in order to reinstate the Phaser multiple tilesets per map capabilities. NOTE: decided this is a stupid approach, see task list below for better idea.
126126

127127
After testing, *all* examples seem to work (with these three restrictions)
128128

129129
Found both bugs, I was effectively applying the scroll twice because the new batch list calculates the offsets internally and I was still applying it as a uniform to the webgl shader.
130130

131131
Remaining Task Summary:
132132

133-
- Change the map parser, so that when additional tilesets are encountered, it creates a new Tilemap Layer for each and keeps data for only one tileset per layer.
133+
- Change the map parser, so that when additional tilesets are encountered, it creates a new Tilemap Layer for each and keeps data for only one tileset per layer. (added TODO: comments into TilemapParser.js for one possible approach to this).
134134
- Store the tileset index or reference in the Tile structure, deprecate resolveTileset and any other related code
135135
- Add alpha blending to the shader, calculate the 'final' alpha by multiplying the layer's worldAlpha with the tile.alpha
136-
- Add scaling to the shader, use the layer's worldScale
136+
- Add scaling to the shader, use the layer's worldScale. (See if rotation can be easily supported too, while doing this)
137137
- Optimise the drawing to avoid degenerate triangles where possible, e.g. each row should be a single tri-strip without degenerates in it for faster drawing
138138

139+
Known bugs:
140+
- Blank Tilemap example isn't drawing, may not handle multiple layers correctly.
139141

142+
Attempted a quick hack to test the new layers approach but got bogged down in the messy class relationship here.
140143

144+
Some notes for later:
145+
- Tilemap creates TilemapLayer objects (Sprites). It keeps no reference to them after adding them to a group (or the world group), the new layer object gets a 'map' reference.
146+
- Tilemap contains a layers member variable, it contains bespoke objects (see createBlankLayer) with some information about layers in the map data (which do not correspond to TilemapLayer objects at all)
147+
- TilemapParser parses raw map data into the Tilemap.data member. It creates Tileset objects and populates them for each tile set used in the raw map. It creates Tile objects for each tile in the map data.
148+
- Tileset contains information about separate tile sources, including the image, the first tile, tile layout in the image. It contains the draw function to render a tile on the canvas.
149+
- Tilemap.createLayer is called by Examples after the Tilemap has been created and parsed.
141150

142-
143-
151+
So, I can't create new TilemapLayer objects in TilemapParser because it will preempt Tilemap.createLayer. Or maybe I can, these TilemapLayer objects will be internal (hidden)...? There aren't any later calls in the Examples which I can extend or adapt, so that might have to be the solution.
144152

0 commit comments

Comments
 (0)