Skip to main content
Apr 12, 2012 9:55 PM UTC
Question

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)

flocky.as

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.moveme()

}



Bird.as

//init Bird

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)

 

flocky.as

myflock = new flock(nrofbirds)

--afterupdate

for (nrofbirds)

{

addchild(flock.birdvector.bImage);   <----------- moved it to here

}

-- 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.moveme()

}



Bird.as

//init Bird xy and set parent flock and stuff



function moveme()

// move bird closer to coord flock.xy

 



--- end --

This topic is closed to new replies. Start a new post to keep the conversation going.

2 replies

Colin Holgate
Inspiring
Apr 13, 2012 3:18 AM UTC

What does the Sprite import line look like in the Bird class?

Translate
Apr 13, 2012 3:26 AM UTC

Hi!

these are my imports in the bird class:

but fyi.. i dont use sprites.. I just addchild the image,

import flash.display.Bitmap;

import flash.geom.Point;

import flash.media.Sound;

import starling.core.Starling;

import starling.display.Image;

import starling.display.Sprite;

import starling.display.Stage;

import starling.events.EnterFrameEvent;

import starling.events.Event;

import starling.events.Touch;

import starling.events.TouchEvent;

import starling.events.TouchPhase;

import starling.extensions.ParticleDesignerPS;

import starling.extensions.ParticleSystem;

import starling.textures.*;

import starling.utils.deg2rad;

 

Translate