In that case, I have to admit that I’m at a loss here 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