how to pass parameters to onAddToScene ?
Shri

Hi,

 

I have a behavior file for 'enemies' in a game.

Some behaviors are the same, while others are enemy type dependent.

Is there a way to pass a parameter to the onAddToScene function so that the enemy type is set?

Or should I  be doing this some other way - setting up a separate object ?

 

thanks

 

All 4 Comments
Elliot

I don't think there is a way to pass parameters to onAddToScene (Gio will confirm that), but this is what I do:

var enemy = new SceneObject(sprite, EnemyBehavior);var behavior = enemy.getBehavior();

And then you can set variables on your behavior object. I usually call an init function with the parameters I want to set for that particular instance of the behavior:

behavior.init(myParameter1, myParameter2);
Shri

Elliot,

 

Yes, I thought about doing it the way you recommended (after I had posted the question - doh! ).

But thanks for the response.

I am still curious if you can pass parameters directly through the onAddToScene function.

 

thanks

Gio

Currently there isn't a way to pass parameters to onAddToScene directly, and what Elliot suggested is a valid alternative.

 

However if you feel it would be useful, I'm sure we could add this to the next version of WADE. You could pass an extra parameter to wade.addSceneObject and WADE would then pass it on to onAddToScene.

Taddeus

I think it can be useful too. Not really necessary but it's nicer syntax I think.

Post a reply
Add Attachment
Submit Reply
Login to Reply