Hello everyone, this is my first post (unfortuantely it had to be something that I’m having difficulties in >.<)
Anywho, I’m not too experienced with FlashPunk so do forgive my ignorance over some things. I wanted to make a small RPG game but didn’t know where to start. So I searched through the web and found a blog that teaches how to basic RPG. I am basically on the second part of the tutorial, which is loading in maps: The RPG Tutorial I’m following.
What I’ve noticed is that this person, at the time of writing the tutorial, was using an older version of OGMO (Version 1.01?). I thought it wouldn’t matter since I can still export XML Coord in the newer version. What the tutorial is basically doing is to have Entities to read in their own XML coordinates and then place in game; essentially, I have Ground entity (collision is done here as well), Tree entity, and Houses Entity. All 3 of which also handle tiles.
Now this is how I want my map to look like:
Instead I, all my tiles are loaded on top of each other on the top left corner (would show pic, but I can neither load a picture or post another link of it). Basically, the tiles are being iterated through, and it seems like it’s all being placed in the same coordinates (I had it traced to see whether it’s even tiling them at all)
So here’s the code that I wrote (from tutorial). Pretty much the same except that I had to place an “@” on the parameter “map.@width” and “map.@height” (in the constructor, graphic = tilemap bit) otherwise I get an error saying invalid BitString.
package entities
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.masks.Grid;
// This class has 2 tasks:
// 1) Read the ground layer data from the OEL file and use it to fill the tile map
// 2) Read the grid layer data from the OEL file and use it to gill the mask property
public class Ground extends Entity
{
// defining the diminesion of tiles and grids
// It's possible to have a grid with smaller grids than tiles for better collisions (not covered here for simiplicity sake)
private const TILE_WIDTH:Number = 48;
private const TILE_HEIGHT:Number = 48;
private const RECT_WIDTH:Number = 48;
private const RECT_HEIGHT:Number = 48;
// Set the tiles.png to class, stored in a constant
[Embed(source = "../assets/gfx/tiles.png")]
private const TILE_SET:Class;
// Tile data and grid data
public var tileMap:Tilemap;
public var grid:Grid;
public function Ground(map:XML) // "map" is a parameter/ map oel that we'll pass on when it's called from another class
{
// label for collision detection (the layer that's a grid-type)
type = "solid";
//setting the graphic property of the entity super class
graphic = tileMap = new Tilemap(TILE_SET, map.@width, map.@height, TILE_WIDTH, TILE_HEIGHT);
trace (map.@width + " " + map.@height)
// Fill tilmap with content
for each (var tile:XML in map.ground[0].tile)
{
tileMap.setTile(tile.@x / TILE_WIDTH,
tile.@y / TILE_HEIGHT,
tileMap.getIndex(tile.@tx / TILE_WIDTH, tile.@ty / TILE_HEIGHT)
);
}
// setting the mask propert of the Entity super class
// No tilemap needed, used for collision
mask = grid = new Grid(map.@width, map.@height, RECT_WIDTH, RECT_HEIGHT);
// fill the tilemap with the content from xml
for each (var solid:XML in map.solid[0].rect)
{
grid.setRect(solid.@x / RECT_WIDTH,
solid.@y / RECT_HEIGHT,
solid.@w / RECT_WIDTH,
solid.@h / RECT_HEIGHT
);
}
}
}
This is the XML file I’m trying to load from: http://pastebin.com/Z4rqKPSX
There is a little difference between my oel and the tutorial’s oel although I wouldn’t think it would matter as much (You may need to downlaod the source code of the tutorial for this particular problem). I understand that there is probably a better way to load in maps, but since this is a continous tutorial I’m following (an old one at that) I thought I could stick with it and then later change it to make it a bit more up to date. I can add the oel provided by the tutorial and use that, it’ll work without a problem, but I’m not sure why I can’t use my own oel’s.
Here’s the tutorial’s oel file: http://pastebin.com/9GtVe0vR
Thank you