OGMO doesn't save properly! [SOLVED]


(John Andersson) #1

Hi.

I had some code which loaded tiles from an ogmo editor XML file and yeah, added it to the stage. Originally, the tileset only had 3 tiles.

I updated the tileset to a lot more, and changed the ogmo level.

Now, when I run the game, the level only loads 3 different tiles! (Another question at the bottom of this)

package
{
import flash.utils.ByteArray;
import net.flashpunk.Entity;
import net.flashpunk.graphics.Tilemap;
import net.flashpunk.masks.Grid;
import flash.geom.Point;
import net.flashpunk.FP;

public class Level extends Entity
{
	private var _tiles:Tilemap;
	private var _ground:Grid;
	private var _wall:Grid;
	public var LevelData:XML;
	public function Level(xml:Class)
	{
		_tiles = new Tilemap(Assets.SPRITE_TILESET, 1920, 1080, 120, 120);
		graphic = _tiles;
		layer = 1;
		
		_ground = new Grid(1920, 1080, 120, 120, 0, 0);
	
		mask = _ground;
		
		type = "ground";
		
		loadLevel(xml);
	}

	private function loadLevel(xml:Class):void 
	{ 
		var rawData:ByteArray = new xml; 
		var dataString:String = rawData.readUTFBytes(rawData.length); 
		LevelData = new XML(dataString);

		var dataElement:XML;
	
		var dataListTiles:XMLList;
		var dataListSpawn:XMLList;
		var dataListWeaponDrop:XMLList;
		var dataListImpSpawn:XMLList;

	
		dataListTiles = LevelData.OurTiles.tile;
		dataListSpawn = LevelData.Entities.Spawn;
		dataListWeaponDrop = LevelData.Entities.WeaponDrop;
		dataListImpSpawn = LevelData.Entities.ImpSpawn;


		for each(dataElement in dataListTiles)
		{
			_tiles.setTile(int(dataElement.@x), int(dataElement.@y), int(dataElement.@tx));
			
			_ground.setTile(int(dataElement.@x), int(dataElement.@y), int(dataElement.@tx) == 0 || int(dataElement.@tx) == 2);
		}
		
					
		

		for each(dataElement in dataListSpawn)
		{
			FP.world.add(new Hero(new Point(int(dataElement.@x), int(dataElement.@y))));
		}

		for each(dataElement in dataListWeaponDrop)
		{
			FP.world.add(new WeaponDrop(new Point(int(dataElement.@x), int(dataElement.@y))));;
		}
		
		for each(dataElement in dataListImpSpawn)
		{
			FP.world.add(new Imp(new Point(int(dataElement.@x), int(dataElement.@y))));;
		}
		
	}
}
}

and the xml file:

<level width="1920" height="1080">
  <OurTiles tileset="Tiles" exportMode="XMLCoords">
    <tile x="0" y="0" tx="5" ty="4" />
    <tile x="0" y="1" tx="5" ty="4" />
    <tile x="0" y="2" tx="5" ty="4" />
    <tile x="0" y="3" tx="5" ty="4" />
    <tile x="0" y="4" tx="5" ty="4" />
    <tile x="0" y="5" tx="5" ty="4" />
    <tile x="0" y="6" tx="5" ty="4" />
    <tile x="0" y="7" tx="5" ty="4" />
    <tile x="0" y="8" tx="0" ty="0" />
    <tile x="1" y="0" tx="5" ty="4" />
    <tile x="1" y="1" tx="5" ty="4" />
    <tile x="1" y="2" tx="5" ty="4" />
    <tile x="1" y="3" tx="5" ty="4" />
    <tile x="1" y="4" tx="5" ty="4" />
    <tile x="1" y="5" tx="5" ty="4" />
    <tile x="1" y="6" tx="5" ty="4" />
    <tile x="1" y="7" tx="5" ty="4" />
    <tile x="1" y="8" tx="1" ty="0" />
    <tile x="2" y="0" tx="5" ty="4" />
    <tile x="2" y="1" tx="5" ty="4" />
    <tile x="2" y="2" tx="5" ty="4" />
    <tile x="2" y="3" tx="5" ty="4" />
    <tile x="2" y="4" tx="5" ty="4" />
    <tile x="2" y="5" tx="5" ty="4" />
    <tile x="2" y="6" tx="5" ty="4" />
    <tile x="2" y="7" tx="5" ty="4" />
    <tile x="2" y="8" tx="1" ty="5" />
    <tile x="3" y="0" tx="5" ty="4" />
    <tile x="3" y="1" tx="5" ty="4" />
    <tile x="3" y="2" tx="5" ty="4" />
    <tile x="3" y="3" tx="5" ty="4" />
    <tile x="3" y="4" tx="5" ty="4" />
    <tile x="3" y="5" tx="5" ty="4" />
    <tile x="3" y="6" tx="5" ty="4" />
    <tile x="3" y="7" tx="5" ty="4" />
    <tile x="3" y="8" tx="7" ty="0" />
    <tile x="4" y="0" tx="5" ty="4" />
    <tile x="4" y="1" tx="5" ty="4" />
    <tile x="4" y="2" tx="5" ty="4" />
    <tile x="4" y="3" tx="5" ty="4" />
    <tile x="4" y="4" tx="5" ty="4" />
    <tile x="4" y="5" tx="5" ty="4" />
    <tile x="4" y="6" tx="5" ty="4" />
    <tile x="4" y="7" tx="5" ty="4" />
    <tile x="4" y="8" tx="4" ty="4" />
    <tile x="5" y="0" tx="5" ty="4" />
    <tile x="5" y="1" tx="5" ty="4" />
    <tile x="5" y="2" tx="5" ty="4" />
    <tile x="5" y="3" tx="5" ty="4" />
    <tile x="5" y="4" tx="5" ty="4" />
    <tile x="5" y="5" tx="5" ty="4" />
    <tile x="5" y="6" tx="5" ty="4" />
    <tile x="5" y="7" tx="5" ty="4" />
    <tile x="5" y="8" tx="4" ty="4" />
    <tile x="6" y="0" tx="5" ty="4" />
    <tile x="6" y="1" tx="5" ty="4" />
    <tile x="6" y="2" tx="5" ty="4" />
    <tile x="6" y="3" tx="5" ty="4" />
    <tile x="6" y="4" tx="5" ty="4" />
    <tile x="6" y="5" tx="5" ty="4" />
    <tile x="6" y="6" tx="5" ty="4" />
    <tile x="6" y="7" tx="5" ty="4" />
    <tile x="6" y="8" tx="4" ty="4" />
    <tile x="7" y="0" tx="5" ty="4" />
    <tile x="7" y="1" tx="5" ty="4" />
    <tile x="7" y="2" tx="5" ty="4" />
    <tile x="7" y="3" tx="5" ty="4" />
    <tile x="7" y="4" tx="5" ty="4" />
    <tile x="7" y="5" tx="5" ty="4" />
    <tile x="7" y="6" tx="5" ty="4" />
    <tile x="7" y="7" tx="5" ty="4" />
    <tile x="7" y="8" tx="4" ty="2" />
    <tile x="8" y="0" tx="5" ty="4" />
    <tile x="8" y="1" tx="5" ty="4" />
    <tile x="8" y="2" tx="5" ty="4" />
    <tile x="8" y="3" tx="5" ty="4" />
    <tile x="8" y="4" tx="5" ty="4" />
    <tile x="8" y="5" tx="5" ty="4" />
    <tile x="8" y="6" tx="5" ty="4" />
    <tile x="8" y="7" tx="5" ty="4" />
    <tile x="8" y="8" tx="5" ty="0" />
    <tile x="9" y="0" tx="5" ty="4" />
    <tile x="9" y="1" tx="5" ty="4" />
    <tile x="9" y="2" tx="5" ty="4" />
    <tile x="9" y="3" tx="5" ty="4" />
    <tile x="9" y="4" tx="5" ty="4" />
    <tile x="9" y="5" tx="5" ty="4" />
    <tile x="9" y="6" tx="5" ty="4" />
    <tile x="9" y="7" tx="5" ty="4" />
    <tile x="9" y="8" tx="1" ty="1" />
    <tile x="10" y="0" tx="5" ty="4" />
    <tile x="10" y="1" tx="5" ty="4" />
    <tile x="10" y="2" tx="5" ty="4" />
    <tile x="10" y="3" tx="5" ty="4" />
    <tile x="10" y="4" tx="5" ty="4" />
    <tile x="10" y="5" tx="5" ty="4" />
    <tile x="10" y="6" tx="5" ty="4" />
    <tile x="10" y="7" tx="5" ty="4" />
    <tile x="10" y="8" tx="1" ty="0" />
    <tile x="11" y="0" tx="5" ty="4" />
    <tile x="11" y="1" tx="5" ty="4" />
    <tile x="11" y="2" tx="5" ty="4" />
    <tile x="11" y="3" tx="5" ty="4" />
    <tile x="11" y="4" tx="5" ty="4" />
    <tile x="11" y="5" tx="5" ty="4" />
    <tile x="11" y="6" tx="5" ty="4" />
    <tile x="11" y="7" tx="5" ty="4" />
    <tile x="11" y="8" tx="1" ty="0" />
    <tile x="12" y="0" tx="5" ty="4" />
    <tile x="12" y="1" tx="5" ty="4" />
    <tile x="12" y="2" tx="5" ty="4" />
    <tile x="12" y="3" tx="5" ty="4" />
    <tile x="12" y="4" tx="5" ty="4" />
    <tile x="12" y="5" tx="5" ty="4" />
    <tile x="12" y="6" tx="5" ty="4" />
    <tile x="12" y="7" tx="5" ty="4" />
    <tile x="12" y="8" tx="7" ty="1" />
    <tile x="13" y="0" tx="5" ty="4" />
    <tile x="13" y="1" tx="5" ty="4" />
    <tile x="13" y="2" tx="5" ty="4" />
    <tile x="13" y="3" tx="5" ty="4" />
    <tile x="13" y="4" tx="5" ty="4" />
    <tile x="13" y="5" tx="5" ty="4" />
    <tile x="13" y="6" tx="5" ty="4" />
    <tile x="13" y="7" tx="5" ty="4" />
    <tile x="13" y="8" tx="4" ty="4" />
    <tile x="14" y="0" tx="5" ty="4" />
    <tile x="14" y="1" tx="5" ty="4" />
    <tile x="14" y="2" tx="5" ty="4" />
    <tile x="14" y="3" tx="5" ty="4" />
    <tile x="14" y="4" tx="5" ty="4" />
    <tile x="14" y="5" tx="5" ty="4" />
    <tile x="14" y="6" tx="5" ty="4" />
    <tile x="14" y="7" tx="4" ty="4" />
    <tile x="14" y="8" tx="4" ty="4" />
    <tile x="15" y="0" tx="5" ty="4" />
    <tile x="15" y="1" tx="5" ty="4" />
    <tile x="15" y="2" tx="5" ty="4" />
    <tile x="15" y="3" tx="5" ty="4" />
    <tile x="15" y="4" tx="5" ty="4" />
    <tile x="15" y="5" tx="5" ty="4" />
    <tile x="15" y="6" tx="5" ty="4" />
    <tile x="15" y="7" tx="4" ty="4" />
    <tile x="15" y="8" tx="4" ty="4" />
  </OurTiles>
  <Entities>
    <WeaponDrop id="0" x="1800" y="720" />
    <ImpSpawn id="1" x="1320" y="720" />
    <Spawn id="2" x="120" y="720" />
  </Entities>
</level>```


As you can see, it only makes the tiles "5" or "1" or "0". I have 56 different tiles in that map!!! Yet it doesn't save properly.

**And also**, how do I make it so that				

    _ground.setTile(int(dataElement.@x), int(dataElement.@y), int(dataElement.@tx) == 0 || int(dataElement.@tx) == 2);

doesn't only add tiles with the name 0 and 2 to the collision group _ground? I wanna make it so that it adds every tile EXCEPT 32 (the background tile), so something like

    _ground.setTile(int(dataElement.@x), int(dataElement.@y), int(dataElement.@tx) != 32);

EDIT: Sorry for the bashing, OGMO. You're actually great

(Jacob Albano) #2

Can you paste the xml in again, this time between triple backticks so the formatting is preserved? I can’t make heads nor tails of that.

```xml
your xml goes here
```

(John Andersson) #3

Alrighty, I fixed it ^^


(Jacob Albano) #4

I usually work with tiles in XML (IDs) mode, so I’m not exactly sure what to do with XML (co-ords). If you change to IDs you can do this:

var tx:int = dataElement.@x;
var ty:int = dataElement.@y;
var id:int = dataElement.@id;
if (id >= 0)
{
    _ground.setTile(tx, ty, id);
}

(John Andersson) #5

Hmm. If I use ID mode, what would Ihave to change in the other parts of the code?? To make it so that their x is the way they were in OGMO.

Oh and do you know why only 3 tiles are being displayed?

Thanks :slight_smile: You’re awesome


(John Andersson) #6

Does anyone know?? :stuck_out_tongue:


(Jacob Albano) #7

It shouldn’t change anything with the positioning of the tiles, just the way the tilemap loads them. I don’t know why only three tiles are showing up, but I suspect it’s due to your misunderstanding something about the loading process, and since I’m not familiar with co-ords mode I can’t help with that.`


(John Andersson) #8

Hmm… I guess I’ll have to look around more. I’ll post if I find the reason!

Btw: The tilemap is 960 x 840, and each tile is 120… if that helps

EDIT: I tried changing some lines in the xml file, changing the first line which was < tile x=“0” y=“0” tx=“5” ty=“4” / > to < tile x=“0” y=“0” tx=“19” ty=“4” / > made it appear as another type of tile. It’s OGMO that isn’t saving correctly D: If you look at the original post, you can see that tx always equals 5 or 0 or something… Stupid OGMO!

Yet another reason to hate OGMO now… it can’t even save properly…


(John Andersson) #9

I started using ID mode and it works. Kinda weird…

Thanks jacob for the tips and help!!


(Jacob Albano) #10

Just because you don’t understand how something works doesn’t mean you should hate it. Ogmo isn’t doing anything wrong; you are, by expecting it to work in a way that’s different than it actually does.

I looked into the way XML coords work. You were expecting it to work with pixel coordinates, but it uses units instead, which makes a LOT more sense.

I created a simple level using this image as a tilemap:

Here’s the level data, containing four tiles laid out just as they appear in the tilemap:

<level width="640" height="480">
  <TileLayer tileset="Tiles" exportMode="XMLCoords">
    <tile x="0" y="0" tx="0" ty="0" />
    <tile x="0" y="1" tx="0" ty="1" />
    <tile x="1" y="0" tx="1" ty="0" />
    <tile x="1" y="1" tx="1" ty="1" />
  </TileLayer>
</level>

The unit coordinates for each tile must be scaled by the dimensions of the tile size.

for each (var tile:XML in level.TileLayer.tile)
{
    var x:Number = TILE_WIDTH * tile.@x;
    var y:Number = TILE_HEIGHT * tile.@y;

    var pixelX:Int = TILE_WIDTH * tile.@tx;
    var pixelY:Int = TILE_HEIGHT * tile.@ty;

    // you now have the position of each tile in the world, 
    // and the top-left of each tile's source in the tilemap
}

I personally don’t know what to do with this data. but I assume it involves usePositions in the Tilemap and Grid classes. Flashpunk works best with IDs, so that’s what I use.

Try not to demean things until you actually understand them.


(John Andersson) #11

You’re right. I was just frustrated. I’m sorry :stuck_out_tongue: Thank you.


(Ultima2876) #12

Ogmo is pretty mature by this point, it’s been around for years. The developers (or someone) would’ve picked up on it by now if it was indeed saving wrong; it’s been used in thousands of games without complaints!

The lesson there; if something isn’t working right in a popular tool or library and a quick google doesn’t show loads of people complaining about it, it’s probably something on your end! :slight_smile:


(John Andersson) #13

Yep :stuck_out_tongue: I am so ashamed of how I reacted. I wish someone could delete this thread to save my reputation :stuck_out_tongue:


(Ultima2876) #14

This topic was automatically closed after 24 hours. New replies are no longer allowed.