[Resolved] Objects, collisions and map scrolling speeds.

Hi,

Not sure if I’m doing this right or the best way…

I have an object layer where I have set properties to allow physics collisions on the objects. The problem is when I set my map to focus on the player the tile layer scrolls as the player moves but the object layer must be staying still as the colisions get all out of sync with the tiles.

Another issue I seem to be having is that the player moves around at the speed I’ve set, but as soon as the map starts scrolling he appears to speed up. I thought this might be just a visual thing as the map is moving with the player but he actually ends up moving of the edge of the screen. Is the idea of map: focus meant to keep the player where he is and move the map around him (for want of a better way of putting it).

Any help/ideas appreciated.

DK. [import]uid: 37683 topic_id: 27891 reply_id: 327891[/import]

Replying to my own post but…

I’ve sussed it. I wasn’t adding the player to the same layer as the tile layer.

map:getTileLayer( “TileLayer” ):addObject(player)

And i’ve moved the physics collision bodies to the tiles themselves rather than overlaying an object layer.

All seems to work as expected now for the movement/scroll speed and the physics.

DK. [import]uid: 37683 topic_id: 27891 reply_id: 112911[/import]

Whiteball, I’m encountering the same problem, attempted to utilize your fix, and still encountered the issue. Are you using the map:setFocus variable as well? Are you inserting your player into the Tile Layer that contains the physics? Any assistance would be appreciated. Thanks! [import]uid: 135394 topic_id: 27891 reply_id: 114513[/import]

In Tiled I set up a layer with my collidable tiles - Called it ‘TileLayer’
These tiles were made physics objects by adding ‘HasBody’ and ‘bodyType’ - ‘Static’ to the tiles properties in the tileset/picker area.

I created my player (also called ‘player’) by loading in an image and making that a physics object in code:
physics.addBody(player)

I added the player to the same layer that the tiles were on:
map:getTileLayer( “TileLayer” ):addObject(player)

I set focus to my player by using my map (named ‘map’) thus:
map:setFocus(player)

It is also important to do these things in the correct order:

  1. load your map - map = lime:loadMap(“MyMap.tmx”)
  2. create the visual - lime:createVisual(map)
  3. create the physical map - lime:buildPhysical(map)
  4. add the player to the tileLayer - map:getTileLayer( “TileLayer” ):addObject(player)
  5. set the map focus to the player - map:setFocus(player)

I have since tweaked mine to have some references to layers and objects for easier manipulation, but the above got me working originally as intended with the map scrolling, following the player and the player colliding into the wall tiles.

Hope it’s clear, if not post an example of your code if possible and I’ll try and help from there.
[import]uid: 37683 topic_id: 27891 reply_id: 114525[/import]

Whiteball, thanks for the info! I found I was borrowing a bit too heavily from the “Platformer” tutorial within Lime, and your explanation helped me out quite a bit. I think I was mostly finding issues when attempting to couple the parallax and camera focus while working with the joystick. I’m a super n00b with the most basic grasp of development. Thanks again for your response! [import]uid: 135394 topic_id: 27891 reply_id: 114813[/import]