File tree Expand file tree Collapse file tree
v3/src/gameobjects/tilemap Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -186,26 +186,23 @@ var Tilemap = new Class({
186186 if ( obj . width ) { sprite . displayWidth = obj . width ; }
187187 if ( obj . height ) { sprite . displayHeight = obj . height ; }
188188
189- // Origin is (0, 1) in Tiled, so shift it to match (0.5, 0.5) in Phaser
190- spriteConfig . x = obj . x + sprite . displayWidth / 2 ;
191- spriteConfig . y = obj . y - sprite . displayHeight / 2 ;
189+ // Origin is (0, 1) in Tiled, so find the offset that matches the Sprite's origin.
190+ var offset = {
191+ x : sprite . originX * sprite . displayWidth ,
192+ y : ( sprite . originY - 1 ) * sprite . displayHeight
193+ } ;
192194
193- // If the object is rotated, then perform an additional correction for the origin
194- // changing from (0, 1) to (0.5, 0.5)
195+ // If the object is rotated, then the origin offset also needs to be rotated.
195196 if ( obj . rotation )
196197 {
197198 var angle = DegToRad ( obj . rotation ) ;
198- var offset = {
199- x : sprite . displayWidth / 2 ,
200- y : - sprite . displayHeight / 2
201- } ;
202199 Rotate ( offset , angle ) ;
203-
204200 sprite . rotation = angle ;
205- sprite . x += offset . x ;
206- sprite . y += offset . y ;
207201 }
208202
203+ sprite . x += offset . x ;
204+ sprite . y += offset . y ;
205+
209206 if ( obj . flippedHorizontal !== undefined || obj . flippedVertical !== undefined )
210207 {
211208 sprite . setFlip ( obj . flippedHorizontal , obj . flippedVertical ) ;
You can’t perform that action at this time.
0 commit comments