Game Development Community

creating a new object

by rennie moffat · in iTorque 2D · 12/13/2010 (5:38 pm) · 7 replies

I know this will seem like a very newbish question as it is. However I am hoping someone can help me out. I am trying to create a new t2dSceneObject in game. So, event happens, this object, blueWall1a is created. Blue wall is this size, position, has this behavior etc. I tried this...

function thisBehavior::onThisEvent(%this)
{
	%blueWall1a = new t2dSceneObject(blueWall1a)
	{
      Position = "-86.209 2.107";
      size = "8.173 30.821";
/// I added in the collisions just so I could see it, as I have collision Bounds visable 
      CollisionActiveReceive = "1";
       CollisionPolyList = "1.000 -1.000 -1.000 1.000";
     };
}

However, when I call the event, I can not see the new object.

One thing that really began to puzzle me is that I added in an echo, into the creation of the object function but instead, I am given an error. If you could please give me a small example of how I can do this. I am hesitant to use clones as each new object must have a behavior attached with slightly different behaviorFields.


I am sorry to ask this as it is probably so easy but I can not figure it out right now.

Thanks

About the author

My thanks to Garage Games and the Garage Games Community combined with owned determination I got one game up, Temple Racer and I am looking to build more interesting, fun games for the mass market of the iOS app store.


#1
12/13/2010 (7:36 pm)
Hi Rennie, it looks to me like you need to specify the scene graph in your object - that way it is added to the scene and will become visible.
#2
12/13/2010 (7:40 pm)
right, so
scenegraph = %this.scenegraph;


I had tried that earlier but maybe was missing something. Is that what you think?


(just working on some other stuff now) will check.
#3
12/13/2010 (8:15 pm)
Depends what "this" is ? Also, what is you image block for blueWall1a ? Has it been loaded? Anything in the console ?
#4
12/13/2010 (8:31 pm)
I have not gotten that far as I am fiddling with some other things, but the object is simply a t2dSceneObject, no sprite involved, just a base imageless object.



%this., in my case, is.. well not sure. I am using a behavior. so this function I am using to create a new t2dSceneObject is called when a puzzle is completed. Then load puzzle 2, puzzle 2 requires a few new objects to be created. These new objects, ex. blueWall1a, needs a behavior attached, with in that behavior it requires specific fields set.

I read this, but had a bit of difficulty, obviously translating it to my needs.

http://tdn.garagegames.com/wiki/TorqueScript/Objects
#5
12/14/2010 (3:23 am)
try

scenegraph = %this.Owner.scenegraph;
#6
12/14/2010 (7:33 pm)
Right. thank you.

:)ggg
#7
12/22/2010 (9:13 pm)
I tried this and of course it worked however, my call is now entering said function as I can see, from an echo... however I am using this, to create a new object. It's correct position is returned, however, no object is scene. I have added the datablock. Any clues?




%this.tB0 = new t2dSceneObject(tB0) {
		scenegraph = %this.owner.scenegraph;
      imageMap = "blueTilesImageMap";
      frame = "1";
      mUseSourceRect = "0";
      sourceRect = "0 0 0 0";
      canSaveDynamicFields = "1";
      UseMouseEvents = "1";
      Layer = "1";
      CollisionActiveReceive = "1";
      CollisionCallback = "1";
      CollisionMaxIterations = "3";
      CollisionPolyList = "-0.211 -0.457 0.525 -0.447 0.211 0.216 -0.560 0.187";
      Immovable = "1";
         mountID = "2";
      _behavior0 = "startTileBehavior	tracer	tracerBlue";
   };