OGMO LevelMinimum/Maximum Size + Level Loading (solved)


(Tareq) #1

Hello, me again! :smile:

Got another question regarding the OGMO editor; I don’t understand what the LevelMinimumSize or LevelMaximumSize do. I guess I should explain what I want in my game; So, some of you may know from my previous thread that I’m following a tutorial (a very old one at that) that teaches you how to make a basic RPG game. Part of the tutorial teaches how to move the camera whilst the player is moving; so I could have a massive map where the player can freely move about and the camera would follow.

Now the problem; I can’t move as much to the right, and when I continue to move down, I get to a point where there are no tiles. I suspect that part of the reason for this has got to do with the level min/max sizes (understand that this old tutorial is using the older version of OGMO). It would help if someone could explain what the two options do (with pretty pictures please :smile:). My default size it 1248x768 and both min and max are set 640x480 and my tiles are 48x48

http://tinypic.com/r/2nw0k79/5 (picture of the untiled area, still can’t post picture yet)

Again, thank you for you help!


(Jacob Albano) #2

Assuming you’re updating FP.camera every frame, something like this should do the trick:

//  Set the camera position first
FP.clampInRect(FP.camera, 0, 0, worldWidth * tileWidth - FP.width, worldHeight * tileHeight - FP.height);

That should keep your camera from panning past the area of the level that has tiles on it.


(Tareq) #3

Thank you for the reply, but that didn’t solve my problem :confounded: Still shows empty space as player moves down


(Jacob Albano) #4

Are you sure you’re running the code I posted after you set the camera position?

In my example, I used worldWidth as the number of tiles that your level is wide, and similarly for worldHeight. Is that how you adapted it for use?


(Tareq) #5

In that case, I have to admit that I’m at a loss here :confused: I hope you don’t mind me pasting my Game class and Camera class:

Game.as

// new packages are to be place in a subfolder with the same name
// which will then be accessed from Main.as via "Import" statement

package worlds
{
import entities.Player;
import entities.Ground;
import entities.Trees;
import entities.House;

import flash.geom.Point;
import net.flashpunk.World;
import flash.utils.ByteArray;
import net.flashpunk.FP;

import utilities.Camera;

public class Game extends World
{
	// embed the map and store in variable
	[Embed(source = "../assets/maps/outdoors_map_01.oel", mimeType="application/octet-stream")]
	private static const OUTDOORS_MAP_01: Class;
	
	public var player:Player
	public var ground:Ground;
	public var trees:Trees;
	public var houseArray:Array = new Array();
	
	public var mapWidth:int;
	public var mapHeight:int;
	
	public var objCamera:Camera;
	
	public function Game()
	{
		//Create player instance and set to (10,10)
		player = new Player(new Point(10, 10));
		
		//Initialise camera
		objCamera = new Camera(200, 2);
		//FP.clampInRect(FP.camera, 0, 0, mapWidth * 48 - FP.width, mapHeight * 48 - FP.height);
		
		// Call function that loads the map
		loadMap();
		
		// Set the camera's starting position to the player
		objCamera.adjustToPlayer(mapWidth, mapHeight, player);
		
	}
	
	override public function update():void 
	{
		objCamera.followPlayer(mapWidth, mapWidth, player);
		//FP.clampInRect(FP.camera, 0, 0, 1248 * 48 - FP.width, 768 * 48 - FP.height);
		super.update();
	}
	
	// Objective: Instantiate all Entities and add them in order
	public function loadMap():void 
	{
		// helper variables
		var o:XML; // used for loop
		var i:int; // used for loop
		
		//Obtain an XML Instance[Embed(source="../assets/maps/outdoors_map_01.oel", mimeType="application/octet-stream")]
		var bytes:ByteArray = new OUTDOORS_MAP_01;
		var xml:XML = new XML(bytes.readUTFBytes(bytes.length)); // Used to parse byte array from OUTDOORS_MAP_01
		
		// Initialise the map variables
		mapWidth = xml.@width;
		mapHeight = xml.@height;
		
		//Build tilemap
		ground = new Ground(xml);
		add(ground);
		
		//load player
		add(player);
		
		// Load trees
		trees = new Trees(xml)
		add(trees);
		
		// Load houses
		
		if (xml.houses) //If there is a xml tag called houses
		{
			i = 0
			for each (o in xml.houses.tile)
			{
				var house:House = new House(i, new Point(o.@x, o.@y), xml);
				houseArray.push(house);
				add(house);
				i++;
			}
		}
		
	}
	
  }// end of class
} // end of package

Camera.as

package utilities 
{
import net.flashpunk.FP;
import entities.Player;

public class Camera 
{
	private var cameraOffset:int;
	private var cameraSpeed:int;
	
	public function Camera(_cameraOffset:int, _cameraSpeed:int) 
	{
		// Initialise camera related values
		cameraOffset = _cameraOffset;
		cameraSpeed = _cameraSpeed;
	}
	
	//Objective: Adjust the camera relative to the player; avoid the camera messing up if the player is
	//			 beyond the boundaries
	public function adjustToPlayer(mapWidth:int, mapHeight:int, player:Player):void
	{
		// Find the coordinates that will centre the player
		var newCameraX:int = (player.x + player.width / 2) - FP.width / 2;
		var newCameraY:int = (player.y + player.height / 2) - FP.height / 2;
		
		// Check if the new coordinates goes beyond map boundaries
		if (newCameraX < 0)newCameraX = 0;
		else if ((newCameraX + FP.width) > mapWidth) newCameraX = mapWidth - FP.width;
		
		if (newCameraY < 0)newCameraY = 0;
		else if ((newCameraY + FP.height) > mapHeight) newCameraY = mapHeight - FP.height;
		
		///Set the new camera coordinates
		FP.camera.x = newCameraX;
		FP.camera.y = newCameraY;
	}
	
	//Objective: Have the camera follow the player if they go near the end boundary of the Flash Window
	public function followPlayer(mapWidth:int, mapHeight:int, player:Player):void
	{
		// Check the horizontal axis
		if (player.x - FP.camera.x < cameraOffset)
		{
			// When the screen's left edge doesn't't hit the right most boundary x=0
			if (FP.camera.x > 0)
			{
				FP.camera.x -= cameraSpeed
			}
		}
		else if ((FP.camera.x + FP.width) - (player.x + player.width) < cameraOffset)
		{
			// When screen's right edge doesn't hit the right most boundary x = mapWidth
			if (FP.camera.x + FP.width < mapWidth)
			{
				FP.camera.x += cameraSpeed;
			}
		}
		
		// Check the vertical axis
		if (player.y - FP.camera.y < cameraOffset)
		{
			// When the screen's upper edge doesn't the upper boundary y=0
			if (FP.camera.y > 0)
			{
				FP.camera.y -= cameraSpeed;
			}
		}
		else if ((FP.camera.y + FP.height) - (player.y + player.height) < cameraOffset)
		{
			// When the screen's bottom edge doesn't hit the lower boundary y=mapHeight
			if (FP.camera.y + FP.height < mapHeight)
			{
				FP.camera.y += cameraSpeed;
			}
		}
		
	}
	
	
}
}

My tiles are 48x48 and the map is 1248x768 Againt, thank you for taking your time helping me


(Abel Toy) #6

If you take a look at your Game.as update code, you can see this line:

objCamera.followPlayer(mapWidth, mapWidth, player);

Looking at your camera code, I can see the followPlayer function asks for a mapWidth, mapHeight and player arguments. Instead, you’re giving your mapWidth as your mapHeight, thus making the camera think your map size is mapWidth x mapWidth.

The line should simply be changed to:

objCamera.followPlayer(mapWidth, mapHeight, player);

And this should fix the issue. You can remove all the lines related to FP.clampInRect because your Camera class already handles this.


(Tareq) #7

I feel stupid now, can’t believe I overlooked this. Thank you very much :cry:

EDIT: I don’t want to start another thread, but would like to know why OGMO gives me a warning everytime a level:

“The selected level is inconsisten with the current project and has been automatically modified to make it loadable. Would you like to save this modified version under a different name before continuing?”

Why can’t I load my level as the way I saved it?


(Abel Toy) #8

Haha, don’t worry. These kinds of mistakes are pretty common and hard to spot. I had to read through the code for about three times before figuring out the mistake.

No idea about the OGMO error. Have you tried saving it as a different name as it says and loading that one? Does it still give the error?


(Tareq) #9

I have, but what it seems to be doing is reducing the dimensions. It’s noticeable since I have quite a big map for a temple, and now it seems to have cut some of it off.

Edit: There is something defientely wrong with OGMO everytime I close the editor and then reopen a level, it seems to corrupt my levels


(Abel Toy) #10

Mhm, maybe it’s a problem with your maxLevelSize? Maybe it must be bigger than your level size, otherwise it gets cropped.


(Tareq) #11

Yeah about that, I still don’t know what Maximum/ Minimum level size is about, something that should’ve been answered in this thread >.<


(Jacob Albano) #12

Max/Min size is just an editor feature. It keeps level designers from making levels that might be too large to work in the game.


(Alex Larioza) #13

Your default size needs to be within your min/max bracket. So if 1248x768 is your maximum map size, your max needs to be the same value or greater.