Spawn function doesn't work!
by Andrea Farid Marsili · in iTorque 2D · 07/30/2011 (2:51 am) · 5 replies
function endlessPlatformOne::spawn(%this){
%platOne = new t2dStaticSprite(){
sceneGraph = %this;
class = endlessPlat;
name = endlessPlatformOne;
layer = 1;
size = "9 120";
};
%platOne.setImageMap(PiattaformaStandardImageMap);
%platOne.setUsesPhysics(true);
%platOne.setWorldLimit(null, -530, -62, 755, 360, true);
%platOne.setWidth(getRandom(160, 250));
%platOne.setPositionX(getRandom(350, 380));
%platOne.setPositionY(getRandom(173, 207));
%platOne.setLinearVelocityX(-200);
}No console error but no object on the screen.
#2
07/30/2011 (1:45 pm)
@Andrea - In addition to what Ken suggested, the new object must be added to the scene graph:%sceneGraph = sceneWindow2D.getSceneGraph(); %sceneGraph.addObject(%platOne);
#3
07/31/2011 (3:22 am)
Okok, now my spawn function work but it run only one time.function endlessPlatformOne::onWorldLimit(%this){
%this.spawn();
%this.safeDelete();
}
function endlessPlatformOne::spawn(%this){
%platOne = new t2dStaticSprite(){
sceneGraph = sceneWindow2D.getSceneGraph();
class = "endlessPlat";
name = "endlessPlatformOne";
layer = 1;
size = "9 120";
};
%
#4
08/08/2011 (10:36 am)
I see what logic you are going for, but something seems off about it. Constantly creating/deleting an object seems kind of wasteful. I think it would be better to create a pool, then recycle objects through that.
#5
08/08/2011 (10:38 am)
Yes now I simply change the position when they are out of the camera
Torque Owner Cassy Brink
Minalien.com
The same goes with your world limit ("NULL" instead of null).
Make sure that the file you're saving this code in is being exec'd somewhere in your game/main.cs file.