Problem in adding behavior on StaticSprite (script)
by ken · in iTorque 2D · 02/22/2012 (1:20 am) · 7 replies
Hi,
I'm trying to add StaticSprites to the Scene with a behavior, but the Behavior does not work! However this behavior works fine when I add it to an object in Game Builder (without scripting)...
here is the script code :
Also I tried this script code:
what is my mistake?
thanks guys!
I'm trying to add StaticSprites to the Scene with a behavior, but the Behavior does not work! However this behavior works fine when I add it to an object in Game Builder (without scripting)...
here is the script code :
function createMyObj(%imageMap,%position)
{
%object = new t2dStaticSprite() {
imageMap = %imageMap;
frame = "0";
mUseSourceRect = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
PlatformTarget = "UNIVERSAL";
Position = %position;
CollisionMaxIterations = "3";
AlphaTestValue = "-1";
mountID = "5";
_behavior0 = "myBehavior";
};
//adding to scene
sceneWindow2D.getSceneGraph().addToScene(%object);
return %object;
}Also I tried this script code:
function createMyObj(%imageMap,%position)
{
%object = new t2dStaticSprite() {
imageMap = %imageMap;
frame = "0";
mUseSourceRect = "0";
sourceRect = "0 0 0 0";
canSaveDynamicFields = "1";
PlatformTarget = "UNIVERSAL";
Position = %position;
CollisionMaxIterations = "3";
AlphaTestValue = "-1";
mountID = "5";
};
//adding behavior
%object.addBehavior(myBehavior.createInstance());
//adding to scene
sceneWindow2D.getSceneGraph().addToScene(%object);
return %object;
}what is my mistake?
thanks guys!
#2
there is no error here.
In addition, I defined datablocks by the script...
take a look at this :
Testing "createMyObj" :
Also I did observe script execution priorities and it works fine with no error... (but still with behavior problem)
02/22/2012 (10:40 am)
No Michael!there is no error here.
In addition, I defined datablocks by the script...
take a look at this :
function getWallImages(%StageNumber)
{
%wallsDirectory = expandFilename("data/images/Stage" @ %StageNumber @ "/Walls");
%Walls = %wallsDirectory @ "/*.png";
%i=1;
for (%file = findFirstFile(%Walls); %file !$= ""; %file = findNextFile(%Walls)) {
$wallimageMaps[%i] = "wallImageMap" @ %i;
%file = getSubStr(%file,0,strlen(%file)-4);
%datablock = setDataBlock(%file, $wallimageMaps[%i]);
$levelDatablocks.add(%datablock);
%i++;
}
}
function setDataBlock(%path,%name)
{
%db = new t2dImageMapDatablock(%name) {
imageName = %path;
imageMode = "FULL";
useHDImage = "0";
frameCount = "-1";
filterMode = "NONE";
filterPad = "0";
preferPerf = "1";
cellRowOrder = "1";
cellOffsetX = "0";
cellOffsetY = "0";
cellStrideX = "0";
cellStrideY = "0";
cellCountX = "-1";
cellCountY = "-1";
cellWidth = "0";
cellHeight = "0";
preload = "1";
allowUnload = "0";
compressPVR = "0";
optimised = "0";
force16bit = "0";
};
return %db;
}Testing "createMyObj" :
getWallImages(1);
$test[1] = createMyObj($wallimageMaps[1],"0 0");Also I did observe script execution priorities and it works fine with no error... (but still with behavior problem)
#4
02/24/2012 (6:14 am)
Sorry, it's tough to parse logic at 6am. I'll test the code at the office in a few hours.
#5
02/24/2012 (1:08 pm)
Have you tried adding the behavior via function calls instead of _behavior0 ?
#6
02/24/2012 (7:11 pm)
As I mentioned in first post, I did use object.addBehavior(myBehavior.createInstance());
#7
02/27/2012 (3:09 am)
Hey Michael, this thread is going to freez...
Employee Michael Perry
ZombieShortbus