Accessing spritemap source ogmo to constructor [Solved]


(Lozza JP) #1

I am trying to use ogmo to place NPC entities and they have a value in OGMO called inputSprite, which points to an embedded source in an Assets class. The Problem is it is a string value in ogmo but in the spritemap constructor it is of type *.

Here is the basic adding part in the world.

		for each (node in mapXML.Entities.NPC)
		{
			add(new NPC(int(node.@initY), int(node.@initX), String(node.@inputSprite)));
		}

and here is the constructor for NPC

	public function NPC(initX:Number, initY:Number, inputSprite:*) 
	{
		this.x = initX;
		this.y = initY;
		layer = 5;
		
		// inputSprite = Assets.EDDY;

		this.spriteNPC = new Spritemap(inputSprite, 29, 35);
		
		spriteNPC.add("Right", [0, 1, 2, 3], 15, true);
		spriteNPC.add("Left", [4, 5, 6, 7], 15, true);
		spriteNPC.add("StandR", [0], 15, false);
		spriteNPC.add("StandL", [4], 15, false);
		spriteNPC.add("JumpR", [8], 15, false);
		spriteNPC.add("JumpL", [9], 15, false);
		graphic = spriteNPC;
		
	}

The string in the ogmo entity is exactly the same as the commented out Assets.EDDY but I keep getting an error invalid source image when trying to run the game. However if the line is uncommented it works fine even though both appear exactly the same.

Do I have to change the ogmo imported entity’s String(inputSprite) to a * or something?


(JP Mortiboys) #2

Assuming that the string value node.@inputSprite resolves to something like EDDY (a static member of the Assets class) then you can do:

// ...
this.spriteNPC = new Spritemap(Assets[inputSprite], 29, 35);
// ...

Otherwise… I’m not sure how you’d expect this to work. As you saw, the Spritemap constructor takes a * type parameter (which must be a BitmapData or a Class (embedded image reference)) - and you want to pass it a string. How would the Spritemap know how to convert a string to a bitmap, unless you tell it?


(Lozza JP) #3

thank you!!

I was trying to do the string resolving the entire thing, Assets.EDDY.

Now just passing the string into Assets[] it works perfect.