Yacob Posted May 12, 2015 Share Posted May 12, 2015 So, I've been working on a game with an overhead perspective, using Tiled maps to make the environment. Some of my sprites aren't tiles, so to make placing them easier, I made a Tiled object containing the coordinates for the player's starting position. My player is a boy in a kayak, so I want that kayak to appear at that coordinate, as well as a sprite of a wooden dock. In create(), I find search the object layer for that "start box" object, store it in a variable, then set positions of my sprites with "startbox.x" and "startbox.y". When I draw the dock, it appears in the place on the map where it should be. However, when I give these values to my movable player, he almost always spawns way at the other end of the map. I say almost always because--mystifyingly enough--a few times some other people that tried my game had reported that the player began next to the dock, but I haven't experienced that, and it was rare for those select players as well. I don't think it's an issue with how I'm getting the map object. I put in the literal coordinates into the player, and I still got the same problem. As soon as I put in coordinates that go over 2000, the sprite seems to start going backwards. Why is this only happening to my player? And how is it that it appeared correctly a handful of times when most of the time it didn't? gmalone 1 Link to comment Share on other sites More sharing options...
gmalone Posted May 13, 2015 Share Posted May 13, 2015 I recall experiencing same issue when teaching students Phaser/Tiled. In that instance, because of time limits, we just did a workaround (coded explicit coords), but am interested in the correct solution. If you haven't yet, have a look inside the exported Tiled JSON file for clues. Perhaps it's a matter of parsing of the right data and setting player.x/y. Link to comment Share on other sites More sharing options...
drhayes Posted May 13, 2015 Share Posted May 13, 2015 It's hard to tell without some code. What does your player declaration look like? What does the relevant section of your Tiled level look like? What about where you position the player? Link to comment Share on other sites More sharing options...
Yacob Posted May 14, 2015 Author Share Posted May 14, 2015 So my player is supposed to spawn near the top right corner of my map. Specifically (3407.57, 214.42) since that's where my "Start" object is on the map. I search for the object like this: map.objects['Meta Layer'].forEach(function(element){ if (element.name === "Start") startBox = element; //contains coords for where dock should be });Then I create my player like this://player spriteplayer = game.add.sprite(startBox.x,startBox.y,'boat_anim');player.anchor.setTo(.5,.5); Link to comment Share on other sites More sharing options...
drhayes Posted May 14, 2015 Share Posted May 14, 2015 Since you're using Tiled... did you resize your physics world? Something like "layer.resizeWorld();" somewhere in your largest layer? Is there any physics code at all for the player in the update method? My general tactic for stuff like this is to start reducing: no physics. Don't create the object from the map (i.e. not in your forEach or your map loading code). Don't animate. What if you drew the position directly using a debug method? You say the dock is fine – is the dock a sprite with physics on it? It might help to see your game, if you're down with that. Link to comment Share on other sites More sharing options...
Recommended Posts