Behaviors not working in iPhone version 1.3
by Dave Rushton · in iTorque 2D · 01/15/2010 (4:07 pm) · 23 replies
I am having an issue with my behaviors on the iPhone. They execute as expected when playing in the game editor but fail to execute at all on the iPhone. They do exist in the resources/game/behaviors folder. I couldn't get my game to compile without creating a new version with iPhone 1.3, but it works great now. I copied my data and behavior folders into the project as per the instructions. I created new level files with the editor. The game won't scroll and it ignores all behaviors except the controls. Do I need to link the behaviors somewhere? If that were case, why would they work in the editor and not on the iPhone? Thanks in advance for your help.
#2
You can manually execute them. Also, check that the code side they are "active" in the iPhone build (not shielded by unit tests or, something).
01/18/2010 (6:54 am)
Yea, it does execute the behaviours that are in the default location.You can manually execute them. Also, check that the code side they are "active" in the iPhone build (not shielded by unit tests or, something).
#3
01/20/2010 (10:39 am)
How do we know they are active, and not shielded by unit tests or something? If I have not changed anything from the default setup it should be cool no? But I get BehaviorComponent::addBehaviors - Missing Behavior on some behaviors.
#4
01/20/2010 (8:13 pm)
I have some behaviors working but have noticed that PlatformerCameraBehavior, and ParallaxObject are not working (among others). These were taken from the behaviors examples on the Torque web site. I also have no idea on how to tell if they are active or shielded. Hopefully someone can help us out on these
#5
I have tried this now on two macs, one running 10.5.8, one with snow leopard. I have the latest Xcode etc. At the top of the project in Xcode is torqueConfig.h there is a line in there #define TORQUE_ALLOW_UNIT_TESTS that is commented out, I guess if we uncomment it then it would be active.
01/21/2010 (1:47 am)
This is definitely some sort of optimization issue, if I drop 10 behaviors in my project and I run it in the simulator I can see they all get included according to the console. even if I only use 1 or 2. When I debug on the phone ONLY the behaviors I actually use show up and only to tell me they do not exist.I have tried this now on two macs, one running 10.5.8, one with snow leopard. I have the latest Xcode etc. At the top of the project in Xcode is torqueConfig.h there is a line in there #define TORQUE_ALLOW_UNIT_TESTS that is commented out, I guess if we uncomment it then it would be active.
#6
01/21/2010 (1:03 pm)
Try adding some echo statements in the behaviour script files to confirm they are being called properly and let us know what happens.
#7
This was an exercise in frustration. a wasted day.
01/21/2010 (6:44 pm)
OK the issue was that my DL of iTGB was not working correctly on my mac, I have re downloaded re installed and ta da... everything works. I don't know how to tell if I have a corrupted file or what, as almost everything worked. This was an exercise in frustration. a wasted day.
#8
01/21/2010 (9:20 pm)
at least, you now have it fixed eh :)
#10
if (!isObject(ParallaxObjectBehavior))
{
%template = new BehaviorTemplate(ParallaxObjectBehavior);
%template.friendlyName = "Parallax Object";
%template.behaviorType = "Effects";
%template.description = "Changes object position based on camera movement.";
%template.addBehaviorField(xSpeed, "Percentage of horizontal scroll speed", float, 100);
%template.addBehaviorField(ySpeed, "Percentage of vertical scroll speed", float, 100);
}
function ParallaxObjectBehavior::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
}
function ParallaxObjectBehavior::onLevelLoaded(%scenegraph)
{
%currPos = sceneWindow2d.getCurrentCameraPosition();
%this.oldPosX = getWord(%currPos, 0);
%this.oldPosY = getWord(%currPos, 1);
}
function ParallaxObjectBehavior::onUpdate(%this)
{
%currPos = sceneWindow2d.getCurrentCameraPosition();
%this.currPosX = getWord(%currPos, 0);
%this.currPosY = getWord(%currPos, 1);
%VectorX = ((%this.currPosX - %this.oldPosX)/100)*(100 - %this.xSpeed);
%VectorY = ((%this.currPosY - %this.oldPosY)/100)*(100 - %this.ySpeed);
%movSpeed = (mAbs(%VectorX) + mAbs(%VectorY))*100;
%objPosX = %this.owner.getPositionX();
%objPosY = %this.owner.getPositionY();
%targX = %VectorX + %objPosX;
%targY = %VectorY + %objPosY;
%this.owner.moveTo(%targX, %targY, %movSpeed);
%this.oldPosX = %this.currPosX;
%this.oldPosY = %this.currPosY;
}
Any suggestions on why this won't work?
01/23/2010 (6:06 pm)
I have managed to get most behaviors working on the iPhone with version 1.3. I can't get the parallax object to work. It is updating as I have put echo statements into it and checked in the console. The code (which is also downloadable on the Torque site) is:if (!isObject(ParallaxObjectBehavior))
{
%template = new BehaviorTemplate(ParallaxObjectBehavior);
%template.friendlyName = "Parallax Object";
%template.behaviorType = "Effects";
%template.description = "Changes object position based on camera movement.";
%template.addBehaviorField(xSpeed, "Percentage of horizontal scroll speed", float, 100);
%template.addBehaviorField(ySpeed, "Percentage of vertical scroll speed", float, 100);
}
function ParallaxObjectBehavior::onBehaviorAdd(%this)
{
%this.owner.enableUpdateCallback();
}
function ParallaxObjectBehavior::onLevelLoaded(%scenegraph)
{
%currPos = sceneWindow2d.getCurrentCameraPosition();
%this.oldPosX = getWord(%currPos, 0);
%this.oldPosY = getWord(%currPos, 1);
}
function ParallaxObjectBehavior::onUpdate(%this)
{
%currPos = sceneWindow2d.getCurrentCameraPosition();
%this.currPosX = getWord(%currPos, 0);
%this.currPosY = getWord(%currPos, 1);
%VectorX = ((%this.currPosX - %this.oldPosX)/100)*(100 - %this.xSpeed);
%VectorY = ((%this.currPosY - %this.oldPosY)/100)*(100 - %this.ySpeed);
%movSpeed = (mAbs(%VectorX) + mAbs(%VectorY))*100;
%objPosX = %this.owner.getPositionX();
%objPosY = %this.owner.getPositionY();
%targX = %VectorX + %objPosX;
%targY = %VectorY + %objPosY;
%this.owner.moveTo(%targX, %targY, %movSpeed);
%this.oldPosX = %this.currPosX;
%this.oldPosY = %this.currPosY;
}
Any suggestions on why this won't work?
#11
02/10/2010 (6:28 pm)
I'm having this problem as well. My behavior is in the default behaviors folder and seems to work fine in the Simulator, but not on Device.
#12
if ( !isObject(Box2dBodyBehavior) )
{
new BehaviorTemplate(Box2dBodyBehavior);
Box2dBodyBehavior.behaviorType = "Box2D integration";
Box2dBodyBehavior.friendlyName = "Box2D Body Behavior";
Box2dBodyBehavior.description = "Makes the owning t2dSceneObject a Box2D body";
Box2dBodyBehavior.addBehaviorField( "Mass", "The mass of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "Inertia", "The inertia of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "CenterOfMass", "The center of mass of the object", Point2F, "0.0 0.0" );
Box2dBodyBehavior.addBehaviorField( "AutoMass", "If true the object's mass/inertia/center is calculated automatically", bool, true );
Box2dBodyBehavior.addBehaviorField( "LinearDamping", "The linear damping coefficient of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "AngularDamping", "The angular damping coefficient of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "AllowSleeping", "Is this object allowed to sleep?", bool, true );
Box2dBodyBehavior.addBehaviorField( "IsSleeping", "Is the object sleeping initially?", bool, false );
Box2dBodyBehavior.addBehaviorField( "FixedRotation", "If true the object will not rotate", bool, false );
Box2dBodyBehavior.addBehaviorField( "IsBullet", "Better tunneling prevents", bool, false );
}
//=----------------------------------------------------------------------------
// Box2dBodyBehavior::getBodyRef()
//=----------------------------------------------------------------------------
function Box2dBodyBehavior::getBodyRef( %this )
{
return %this.bodyRef;
}
//=----------------------------------------------------------------------------
// Box2dBodyBehavior::onRemoveFromScene()
//=----------------------------------------------------------------------------
function Box2dBodyBehavior::onRemoveFromScene( %this )
{
t2dAssert( %this.owner.box2d_can_be_removed,
"Warning - Box2dBody sceneObject not removed through Box2dWorldRef::destroyBody()" );
}
02/11/2010 (5:55 pm)
I have the same problem.In simulator behaviors works fine, but not on device. if ( !isObject(Box2dBodyBehavior) )
{
new BehaviorTemplate(Box2dBodyBehavior);
Box2dBodyBehavior.behaviorType = "Box2D integration";
Box2dBodyBehavior.friendlyName = "Box2D Body Behavior";
Box2dBodyBehavior.description = "Makes the owning t2dSceneObject a Box2D body";
Box2dBodyBehavior.addBehaviorField( "Mass", "The mass of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "Inertia", "The inertia of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "CenterOfMass", "The center of mass of the object", Point2F, "0.0 0.0" );
Box2dBodyBehavior.addBehaviorField( "AutoMass", "If true the object's mass/inertia/center is calculated automatically", bool, true );
Box2dBodyBehavior.addBehaviorField( "LinearDamping", "The linear damping coefficient of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "AngularDamping", "The angular damping coefficient of the object", float, 0.0 );
Box2dBodyBehavior.addBehaviorField( "AllowSleeping", "Is this object allowed to sleep?", bool, true );
Box2dBodyBehavior.addBehaviorField( "IsSleeping", "Is the object sleeping initially?", bool, false );
Box2dBodyBehavior.addBehaviorField( "FixedRotation", "If true the object will not rotate", bool, false );
Box2dBodyBehavior.addBehaviorField( "IsBullet", "Better tunneling prevents", bool, false );
}
//=----------------------------------------------------------------------------
// Box2dBodyBehavior::getBodyRef()
//=----------------------------------------------------------------------------
function Box2dBodyBehavior::getBodyRef( %this )
{
return %this.bodyRef;
}
//=----------------------------------------------------------------------------
// Box2dBodyBehavior::onRemoveFromScene()
//=----------------------------------------------------------------------------
function Box2dBodyBehavior::onRemoveFromScene( %this )
{
t2dAssert( %this.owner.box2d_can_be_removed,
"Warning - Box2dBody sceneObject not removed through Box2dWorldRef::destroyBody()" );
}
#13
Box2D on iphone .... yupiiiii !!!!
02/11/2010 (7:00 pm)
ok i load it manualy from projectManagment.cs [ exec("game/behaviors/blah blah.cs");.... ] and now works fine.Box2D on iphone .... yupiiiii !!!!
#14
02/12/2010 (3:21 pm)
Lorenzo, what part of projectManagement.cs are you putting that code?
#15
....
....
//---------------------------------------------------------------------------
// Behaviors
//---------------------------------------------------------------------------
addResPath(%behaviorsDirectory);
//my behaviors
exec("game/behaviors/Box2dBodyBehavior.cs");
exec("game/behaviors/Box2dShapeBehavior.cs");
//
// Compile all the cs files.
%behaviorsSpec = %behaviorsDirectory @ "/*.cs";
for (%file = findFirstFile(%behaviorsSpec); %file !$= ""; %file = findNextFile(%behaviorsSpec))
compile(%file);
...
...
...
bye
02/16/2010 (2:26 pm)
after line 99....
....
//---------------------------------------------------------------------------
// Behaviors
//---------------------------------------------------------------------------
addResPath(%behaviorsDirectory);
//my behaviors
exec("game/behaviors/Box2dBodyBehavior.cs");
exec("game/behaviors/Box2dShapeBehavior.cs");
//
// Compile all the cs files.
%behaviorsSpec = %behaviorsDirectory @ "/*.cs";
for (%file = findFirstFile(%behaviorsSpec); %file !$= ""; %file = findNextFile(%behaviorsSpec))
compile(%file);
...
...
...
bye
#16
02/21/2010 (5:29 am)
I'm starting to think maybe I have a corrupted download like Henry. I can't get behaviors working in the simulator. They work in the editor. They are executing in the simulator since i'm echoing off the vector in faceObject.cs and getting output to the console. Any suggestions before I do some scorched earth?
#17
02/21/2010 (5:12 pm)
Looks like I screwed up something. Started over using the iPhone test example with the bouncing balls where I knew the behavior was working in simulator. Added my behaviors in one by one some work some don't. I'm guessing some just won't work out of the box. Glad that I have a couple working at least.
#18
02/21/2010 (5:26 pm)
Are you suing included behaviors, or behaviors that you have written? Which ones specifically do not work?
#19
02/21/2010 (7:24 pm)
Was trying to get faceObject.cs to work. I have timerShoot.cs working but doesn't work as I need if it can't face the object I need it to.
#20
02/21/2010 (7:48 pm)
I thought that none of behaviors were working in the editor but not on the iPhone or simulator. After I tested them further I found out the real problem was getting the behaviors to execute in the order that I wanted and after the objects they were linked to were created. I was unable to find a solution for that.
Torque Owner Dave Rushton