Author Topic: [SOLVED] Tiles and Map Doubts (Perharps problemns)  (Read 1963 times)

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
I'm new at AS3 and Flixel, and i found myself really confortable learning AS3 from Flixel code, and of corse some AS3 study...
But i'm having so much problemns on "how to map".
I made my tiles, and done the arrays for it, but i cant find a way to map it, every time i run, the player falls into an abyss.
I'm basing myself on EZPlataform, Mode, and Collision Demo.
I found that EZPlataform would be greater, becoz the map is array to cvs based, but mode and collision are random generated - what makes me more confused.

So, i beg someone for help, what i did, is this:

Code: [Select]
override public function create():void
{
var data:Array = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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2,10,10,0,1,4,7,1,1,7,1,1,7,1,1,1,1,7,1,1,1,4,4,7,1,1,7,1,1,4,1,1,7,1,1,1,7,4,1,1,4,1,1,7,1,1,1,1,8,
9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11,
9,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11);

var t:FlxTilemap = new FlxTilemap();
t.auto = FlxTilemap.ALT;
t.loadMap(FlxTilemap.arrayToCSV(data,36),ImgTiles);
t.follow();
add(t);
(...)
« Last Edit: Thu, Jul 1, 2010 by luciebara »
-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-

cai

  • Contributor
  • ****
  • Posts: 465
  • Karma: +0/-0
  • the illest of villains
    • View Profile
    • Brandon Cash
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #1 on: Tue, Jun 29, 2010 »
You need to specifically do collisions with the map.  In your update loop, do something like this:
Code: [Select]
t.collide(player);

It's worth noting that you will need to move t, your FlxTilemap instance, into object scope (at the top of the object, not inside create()).  You will also need to change player to the object which you want to collide.
Follow me on Twitter | Come join us at #flixel on irc.freenode.net!

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #2 on: Wed, Jun 30, 2010 »
I think i forgot to mention, actually, i think the collide is working, but as the map doesnt gets on the screen, i cant see if is correct or not.
The all problemn is the map, that doesnt appear, makin the player falls into nothing.

But thank you anyways ;3
-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-

biomechanic

  • Active Member
  • ***
  • Posts: 107
  • Karma: +0/-0
    • View Profile
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #3 on: Wed, Jun 30, 2010 »
You say you are basing your thing on EZPlatformer, so I'll assume that the stage is 320x240 with double size pixels and camera doesn't follow player.

Your map is 36x24 tiles, so if the individual tile is taller than 10px the bottom ones won't fit on the screen. At 12px the only 20 rows will show and those are all 0 in your map.

Also: if your '0' tile is not an empty, you should set tilemap's drawIndex to 0, the deafult is 1.

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #4 on: Wed, Jun 30, 2010 »
You say you are basing your thing on EZPlatformer, so I'll assume that the stage is 320x240 with double size pixels and camera doesn't follow player.

Your map is 36x24 tiles, so if the individual tile is taller than 10px the bottom ones won't fit on the screen. At 12px the only 20 rows will show and those are all 0 in your map.

Also: if your '0' tile is not an empty, you should set tilemap's drawIndex to 0, the deafult is 1.

Hm, it is 320x240, but i added the follow information...
the tiles are 20x20...
but let me try to understaind, you said that maybe the height of the map could be the problemn?
-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-

biomechanic

  • Active Member
  • ***
  • Posts: 107
  • Karma: +0/-0
    • View Profile
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #5 on: Wed, Jun 30, 2010 »
With 20x20px tiles only 12 rows will fit on screen.

I've just noticed another problem, wich may or may not be at fault here. Your array is 64 tiles wide, 24 tall - total 1536 tiles. In the arrayToCSV() call you give 36 as the width, which would give 42,666 rows.

Delete first 12 rows of the array and change the width to 64. See if it helps.

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #6 on: Wed, Jun 30, 2010 »
Still not works :(
-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #7 on: Wed, Jun 30, 2010 »
I think the real problemn is how to load the img, i think it isnt loading.
i got the tileset embed with the Class of ImgTiles, and i dindt found how to incorporate it to the script, so i done this:

Code: [Select]
t.loadMap(FlxTilemap.arrayToCSV(data,64),ImgTiles);
perharps it isnt the way to load it?
-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-

biomechanic

  • Active Member
  • ***
  • Posts: 107
  • Karma: +0/-0
    • View Profile
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #8 on: Wed, Jun 30, 2010 »
It is the way.
Post your code as it is now and your tile image.

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #9 on: Wed, Jun 30, 2010 »
Ok, the code:

Code: [Select]
package
{
import org.flixel.*;

public class PlayState extends FlxState
{
[Embed(source="data/tileset2.png")] private var ImgTiles:Class;

protected var _player:FlxSprite;
protected var _fading:Boolean;

override public function create():void
{
var data:Array = new Array( 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0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,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,10,11);

var t:FlxTilemap = new FlxTilemap();
t.auto = FlxTilemap.ALT;
t.loadMap(FlxTilemap.arrayToCSV(data,64),ImgTiles);
t.follow();
add(t);

FlxG.mouse.hide();

FlxState.bgColor = 0xFFACBCD7;

add(new Player(32,176));
}
override public function update():void
{
super.update();
collide();
}
}
}

The Tileset:

-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-

biomechanic

  • Active Member
  • ***
  • Posts: 107
  • Karma: +0/-0
    • View Profile
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #10 on: Wed, Jun 30, 2010 »
Your to-do list for today:
1) remove this line
Code: [Select]
t.auto = FlxTilemap.ALT;I haven't played with it (or even known that it existed) but from the way it is used in EZPlatformer I'd assume that your map should be made of zeroes and ones, and appropriate tiles would be selected from your image automatically based on their position. If you map the tiles yourself, which you do, delete the line.

2) add tile size to the loadMap call, so that this
Code: [Select]
t.loadMap(FlxTilemap.arrayToCSV(data,64),ImgTiles);becomes that
Code: [Select]
t.loadMap(FlxTilemap.arrayToCSV(data,64),ImgTiles,20,20);By default FlxTilemap takes your image's height (40px) and uses it as tile height and width, so your 9 rows of zeroes are not 180px high, but 360px - the non-zero tiles still won't fit on screen.
Also: with 40px as width you end up with 4.5 tiles in your strip which may mess things up.

Try this and do tell if it helps.

luciebara

  • Member
  • **
  • Posts: 15
  • Karma: +0/-0
    • View Profile
    • Midnight'mare (My Band ;D)
Re: Tiles and Map Doubts (Perharps problemns)
« Reply #11 on: Thu, Jul 1, 2010 »
Oh thank you!
I where really wondering how flixel would found the x and y from the tile. hahaha
Thank you really really much, it finally worded :}
-
I am not a human anymore, I traded my attitude and I traded my spine, placid weak as piss wanna **** in my car?
-