Author Topic: Flixel tilemap sinking  (Read 1191 times)

flippinmental

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Flixel tilemap sinking
« on: Fri, May 13, 2011 »
Firstly;

Hello Flixel forums!

I've been using flixel for a few months now, and decided to create a test game just to teach myself. Anyway up till now I've had very few problems at least none in which I felt the need to post on the forums. I've searched and I can't find any problem like this.

Basically all the objects I have placed on my tile map using the following code;
Code: [Select]
public function convert_map() : void
        {
            for (var i:int = 0; i < tilemap.totalTiles; i++ )
            {
                var t:int = tilemap.getTileByIndex(i);
                // Spikes tiles
                if (t == 3)
                {
                    tilemap.setTileByIndex(i, 0);
                    var spike:FlxSprite = new FlxSprite (i % tilemap.widthInTiles * 16, i / tilemap.widthInTiles * 16 -1);
                    spike.loadGraphic(img_spikes,true,false,16,16);
                    spike.immovable = true;
                    group_spikes.add(spike);
                }

All items placed like this seem to sink into the tilemap by a few pixels every 3 columns. So by the time you get to the end of the map objects have almost entirely sunk into the tilemap.

I've been basing my game off the tutorial here(http://users.wpi.edu/~bmoriarty/imgd1001/tutorials/tut4.html) and this dosnt seem to have the same problem. I've deleted large chunks of code to see whats causing it and nothing makes a difference so I really dont know whats going on.

Anyway that can help it would be awesome, as I really dont know why its doing this. It may be something really stupid and I am new to flixel so maybe I've forgotten to do something.

Oh and Im using the latest master of flixel.

http://flippinmental.deviantart.com/art/Duck-Tales-prototype-2-208678466
You can play the game here to see what I mean. Look at the spikes and the blocks in the lower right when you start. Look at how the first spike in the row is slightly higher then the other two.

goog

  • Member
  • **
  • Posts: 12
  • Karma: +0/-0
  • my blog: http://michaelcurtiss.blogspot.com/
    • View Profile
    • my blog
Re: Flixel tilemap sinking
« Reply #1 on: Fri, May 13, 2011 »
try this maybe?
also, what is that -1 in the y placement value doing?

Code: [Select]
var spike:FlxSprite = new FlxSprite (i % tilemap.widthInTiles * 16, Math.floor(i / tilemap.widthInTiles) * 16 -1);
« Last Edit: Fri, May 13, 2011 by goog »

flippinmental

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Flixel tilemap sinking
« Reply #2 on: Fri, May 13, 2011 »
try this maybe?
also, what is that -1 in the y placement value doing?

Code: [Select]
var spike:FlxSprite = new FlxSprite (i % tilemap.widthInTiles * 16, Math.floor(i / tilemap.widthInTiles) * 16 -1);

Ah-ha! Thankyou! Thats worked, cheers! The -1 was just to position them more nicely(so offset basically), but its not needed now. The code was originaly written for an older version of flixel so im guessing it was needed there.
« Last Edit: Fri, May 13, 2011 by flippinmental »