Author Topic: Colliding with more than one FlxTilemap?  (Read 1074 times)

edmundito

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Colliding with more than one FlxTilemap?
« on: Fri, Dec 14, 2012 »
I'm running some experiments with Flixel in that I have a State with the following hierarchy:

State
+ Group
--+ Tilemap 1 (x offset to - tilemap's width)
--+ Tilemap 2
--+ Tilemap 3 (x offset to + tilemap's width)
+ Player Sprite

Using the master version of Flixel ("2.5"?) I'm using the FlxCamera to follow the player, and the whole goal of having the three tile maps is to create an endless world.

However, with a very simple collision on the State update() call:
Code: [Select]
FlxG.collide(tileGroup, playerSprite);

It only collides with the FlxTilemap at position (0, 0) (tilemap 2 in the example).

Am I pushing Flixel to do something that does not support (offset Tilemaps)?
« Last Edit: Sat, Dec 15, 2012 by edmundito »

wg/funstorm

  • Global Moderator
  • Key Contributor
  • *****
  • Posts: 596
  • Karma: +0/-0
    • View Profile
    • Funstorm
Re: Colliding with more than FlxTilemap?
« Reply #1 on: Fri, Dec 14, 2012 »
Might be a worldBounds problem. Flixel only checks collision within a certain area for performance reasons. Check out 'level size': http://www.funstormgames.com/blog/2011/10/flixel-setting-up-game-dimensions-swf-camera-level-hud-mouse/

edmundito

  • New Member
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Colliding with more than FlxTilemap?
« Reply #2 on: Sat, Dec 15, 2012 »
Ah, that explains it!

It turns out that FlxCamera::setBounds very last parameter that can update the worldBounds:

Code: [Select]
public function setBounds(X:Number=0, Y:Number=0, Width:Number=0, Height:Number=0, UpdateWorld:Boolean=false):void
{
if(bounds == null)
bounds = new FlxRect();
bounds.make(X,Y,Width,Height);
--> if(UpdateWorld)
--> FlxG.worldBounds.copyFrom(bounds);
update();
}

So I adjust the camera and world bounds as I move my tiles around. And now my endless scrolling background works! Thanks!
« Last Edit: Sat, Dec 15, 2012 by edmundito »