stage gone in addchild? or where do they go
Ls,
Practicing OOP and trying out starling I made a small flock routine that whirls stuff around the screen.
Although you can afcourse do this the easy way 1 one class with some vectors, i restrained myself and tried it OOP (patting myself on the back).
However I noticed that when I use addchild in the lowest/last class Bird. It doesnt complain but also doesnt apear on screen.
After moving the addChild(Image) up to the main class started by new Starling(flocky, stage) they appear?!
For this I created a vector that gets filled by the bird class then i loop through it adding them to stage.
I wanted to not do that for change but havent managed to get it working otherwise.
I tried passing the stage (starling.display.DisplayObject.stage) thru the constructors to the bird class but that doesnt work (or I just dont know how).
(for those willing to help I added some pseudo code at the end of this page)
Q's:
Is the main class the only place where you can add to stage?
Is it possible/disirable to make stage global or something? (all classes have starling.display.sprite as superclass)
Please advice,
Highest regards,
Mac
//
PSEUDOCODE
// code below compiled and runs but nothing is seen on stage
new Starling(flocky, stage)
myflock = new flock(nrofbirds)
-- enterframe event
myflock.moveall();
flock.as
// init flock xy and stuff
for (nrofbirds)
{
tBird = new (bird)
birdvector.push(tBird)
}
function moveall()
// move flock
for (nrofbirds)
{
birdvector
}
Bird.as
addChild(Image); <------- adding to stage on construction.
function moveme()
// move bird closer to coord flock.xy
----------------------------------------------------------------------------------------
// when moving the addchild to the main class it works
// but why?
new Starling(flocky, stage)
myflock = new flock(nrofbirds)
--afterupdate
for (nrofbirds)
{
addchild(flock.birdvector
}
-- enterframe event
myflock.moveall();
flock.as
// init flock xy and stuff
for (nrofbirds)
{
tBird = new (bird)
birdvector.push(tBird)
}
function moveall()
// move flock
for (nrofbirds)
{
birdvector
}
Bird.as
//init Bird xy and set parent flock and stuff
function moveme()
// move bird closer to coord flock.xy
--- end --
