Hello pixelschaos
If one of these objects is simple enough to be a sprite, your text for example, you could do the following.
duck.addSprite(text, {x:0. y:0});
This would add a sprite to the duck object, that would be a specified offset from the objects center, in this case, 0, 0.
If however you do want objects to follow one another, I do not think there is a function to do that currently, however I can see it being a reasonably common case so we might look into the possibility of adding it.
The way I have done this in the past is the way you have done it using onUpdate, here is a simple example, that I have not tested :p but should work.
var duckSprite = new Sprite("rubberDuck.png");var duck = new SceneObject(duckSprite);wade.addSceneObject(duck)var text = new TextSprite("I am the batman", "32px Arial", "red", "center");var textObj = new SceneObject(text);textObj.parentObj = duck;textObj.onUpdate = function(){ this.setPosition(this.parentObj.getPosition().x, this.parentObj.getPosition().y);};wade.addSceneObject(textObj, true);
* Notice the true in addSceneObject, this is very important, it tells the object to listen for events, these event functions must be declared before adding to the scene, else you will need to use the wade.addEventListener function.
In the above example, using addSprite for the text would be better than having 2 scene objects, but when you do have 2 scene objects, the above example should work.
You could alter the on update function to add an offset so that the text was not directly on the ducks position eg
var offset = {x:10, y:30};
this.setPosition(this.parentObj.getPosition().x + offset.x, this.parentObj.getPosition().y + offset.y);
You could also make the text object move gradually towards the duck, by finding the vector between them, and only modifying the texts position by a fraction of that each frame.
I hope this answers your question, if you have any problems, please reply to this thread, good luck :)