Actor on specific layer

JoyfulDreamer

  • Posts: 56
How do I create an actor on a SPECIFIC layer. If there's no block, just give me the API function(s) to use, thanks! :)
Free music at JoyfulDreamer.com and GameMusicWorld.com.

coleislazy

  • *
  • Posts: 2607
createActor(type,x,y,layerConst);

EDIT: His way is probably better.
|
|
V

« Last Edit: July 04, 2011, 10:36:41 am by coleislazy »

Blob

  • *
  • Posts: 722
Alternatively for anyone who wants to stay in design mode, you can go to Actor -> Draw, where there's a layer subcategory that can send an actor to a specific layer upon creation.

~ Blob

JoyfulDreamer

  • Posts: 56
createActor(type,x,y,layerConst);

Is that really for a SPECIFIC layer? It takes a layer constant, not a layer ID.
Free music at JoyfulDreamer.com and GameMusicWorld.com.

coleislazy

  • *
  • Posts: 2607
Touche. Blob's way is better in any case.

JoyfulDreamer

  • Posts: 56
Still, would be nice to be able to create an actor on a layer on one go, but that works, thanks. :)
Free music at JoyfulDreamer.com and GameMusicWorld.com.

Hectate

  • *
  • Posts: 4643
Keep in mind that you have to create the layer in the scene designer in order to place/move actors on/to it using behaviors.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.

Alexin

  • *
  • Posts: 3130
I use the following method to move an actor to a specific layer:
Code: [Select]
private function moveActorToLayer(target:Actor, layerID:int):Boolean
{
if(target.getLayerID() == layerID) return true;

target.bringToFront();

while(target.getLayerID() != scene.getBottomLayer())
{
target.sendBackward();

if(target.getLayerID() == layerID) return true;
}

return false;
}



And I use this one to get a layer's ID, given its name:
Code: [Select]
private function getLayerID(name:String):int
{
for each(var tileLayer:TileLayer in scene.tileLayers)
{
if(tileLayer.name == name)
{
return tileLayer.layerID;
}
}

return -1;
}
"Find the fun"
alexin@stencyl.com