Game Development Community

Question On the Blaster tutorial for TX 2.0

by Shakey · in Torque X 2D · 04/15/2009 (6:59 am) · 1 replies

Studying the code, I just have a quick question, In the protected void _Fire() function, the projectileObj.Layer is being assigned the SceneObject.Layer + 1, which I think means adding to the projectile's layer property, currently at 0, the ships layer property, currently at 0, then adding 1 to it, giving the projectile's layer value a 1, is this correct. If so why are we giving the projectile this layer. Please could some one explain.

And Could someone give me a quick explanation of this code.

int DirectionX = (TargetX > SceneObject.Position.X) ? 1 : -1;



#1
04/15/2009 (9:18 am)
Quote:If so why are we giving the projectile this layer. Please could some one explain.

Aside from the benefits of maintaining a well-organized project I've found that when you don't explicitly assign objects to a layer you can get a situation where objects on the same layer overlap and flicker.

Quote:And Could someone give me a quick explanation of this code.

That's a ternary operation which could be translated as, "If TargetX is greater than SceneObject.Position.X set DirectionX to 1; in any other situation set DirectionX to -1".

Since TX uses a Cartesian coordinate system (flipped over the X-axis, making up -y, right +x, down +y and left -x) this statement is setting DirectionX to right if the target is to the right and left if the target is to the left.