Here is my code trying to factor in your suggestions (beforehand used a call to my GameWorld class). We are using OGMO to create levels and have the doors working well as entities we place in ogmo and give an index number. It’s just trying to get some tooltip text to display.
This currently throws a 1009 error that it cannot access a propery or method of a null object reference, but I can’t figure out why. My understanding is it thinks no new Text has been instantiatied?
Also it is in the update method, I had it working previously using a call to my gameworld class and it was adding entities really fast, I am guessing 1 per frame. So can I put it just in the main method somehow?
import net.flashpunk.Entity;
import net.flashpunk.utils.*;
import net.flashpunk.FP;
import net.flashpunk.World;
import net.flashpunk.graphics.Text;
import entities.Player;
import GameWorld;
public class DoorWay extends Entity
{
private var targetX:Number;
private var targetY:Number;
private var targetLevel:Class;
private var level:GameWorld;
private var index:int;
private var doorText:Text = new Text("", 0, 0);
private var gameWorld:GameWorld = world as GameWorld;
/**
*
* @param level - the current level, this is necessary becuase this calls functions my game world that do not exist in the base flashpunk world.
* @param x - the x position to place the doorway.
* @param y - the y position to place the doorway.
* @param targetX - the x position where the player character will start in the level this door leads to.
* @param targetY - the y position where the player character will start in the level this door leads to.
* @param index - used to determine the level that this door leads to.
*/
public function DoorWay(level:GameWorld, x:Number, y:Number, targetX:Number, targetY:Number, index:int, doorName:String="")
{
this.level = level;
this.x = x;
this.y = y;
this.targetX = targetX;
this.targetY = targetY;
this.index = index;
setHitbox(24, 24);
// Assign index in ogmo or level oel/xml doorway.index, put the reference here in case # to the level to go to.
switch (index)
{
case 0:
targetLevel = Assets.TESTLEVEL;
break;
case 1:
targetLevel = Assets.STREETLEVEL;
break;
case 11:
targetLevel = Assets.SEWERLEVEL;
break;
case 12:
targetLevel = Assets.SKYLEVEL;
break;
case 2:
targetLevel = Assets.HOMELEVEL;
break;
case 21:
targetLevel = Assets.BEDROOMLEVEL;
break;
case 3:
targetLevel = Assets.PARKLEVEL;
break;
case 4:
targetLevel = Assets.MALLLEVEL;
break;
case 5:
targetLevel = Assets.MOXENLEVEL;
break;
case 6:
targetLevel = Assets.FACTORYLEVEL;
break;
case 7:
targetLevel = Assets.LABLEVEL;
break;
case 8:
targetLevel = Assets.TOWERLEVEL;
break;
}
}
override public function update():void
{
if (collide("player", x, y))
{
doorText = new Text("test", 400, 400);
gameWorld.addGraphic(doorText);
// Goes in the doorway.
if (Input.pressed(Key.C))
{
// Creates new world with targetLevel, and puts player at targetX and Y
// I am assuming the old world is lost in memory/deleted.
// I don't think it is -laurence.
FP.world = new GameWorld(targetLevel, targetX, targetY);
}
}
// Creates a reference to eddy, so we can do player.x for his location.
var player:Player = world.getInstance("eddy") as Player;
// Checks if eddy is close to the door ~2 blocks. When we get remove text working remember to
// reverse the <.
if (FP.distance(player.x, player.y, x, y) > 48) // (FP.distance(player.x, player.y, x, y) > 5)
{
trace("You are not close to the door.");
}
} // end update function
}
My logic is that doorName in the constructor gets a string we put in ogmo editor. Then I want to get the Text object working by (doorName, player.x, player.y).