Game Development Community

How to add PSK Platformer Behavior by script

by Kayrel Parcen Vandal · in TGB Platformer Kit · 10/28/2008 (12:34 pm) · 6 replies

Hello people:

Does anybody know how to add the existing PSK behaviors to a dynamically created object by script? The object is created by mouse clicks and needs to have PSK behaviors like Platform Behavior to interact with the actors in the game. Because is created this way I can not add PSK behaviors as usual in TGB.

function sceneWindow2D::onRightMouseDragged( %this, %mod, %worldPos, %mouseClicks )
{
%myObject = new t2dStaticSprite()
{
SceneGraph = %this.getSceneGraph();
ImageMap = myImageMap;
Position = %worldPos;
};
// Now, how do to assign PSK behaviors to this object???
}

Thanks.

#1
10/28/2008 (12:40 pm)
When I come across issues like this, I create a blank scene, add the object that I want to create in script and then open up the t2d file to view the code.

%myObject = new t2dStaticSprite()
{
    SceneGraph = %this.getSceneGraph();
    ImageMap = myImageMap
    Position = %worldPos;
    
    _Behavior0 = "BehaviorName" TAB "myField" TAB "myField_Value" TAB "myField2" TAB "myField2_Value";
    _Behavior1 = ...
};
#2
10/28/2008 (1:02 pm)
I've seen this question pop up a few times this month, but no one posted this:

When I try to dynamically create an object from script, sometimes nothing happens. It's as if the object is never spawned. If this happens to you, and you have no errors or warnings, make sure you've assigned a scenegraph or added the object to the scene:

t2dSceneGraph::addToScene(...)
#3
10/29/2008 (7:22 am)
Hello P.O. & M.P.:

Thanks for your reply. I tried it but it did not work. I also tried it as seen in behavior's forum, but nothing:

function sceneWindow2D::onRightMouseDragged( %this, %mod, %worldPos, %mouseClicks )
{
%myObject = new t2dStaticSprite()
{
SceneGraph = %this.getSceneGraph();
ImageMap = myImageMap;
Position = %worldPos;
_Behavior0 = "PlatformBehavior" TAB "OneWay" TAB "false" TAB "SurfaceFriction" TAB "1.0" TAB "SurfaceForce" TAB "0.0";
};
}

and...

_Behavior0 = "PlatformBehavior" "OneWay" "false" "SurfaceFriction" "1.0" "SurfaceForce" "0.0";

and...

_Behavior0 = "PlatformBehavior OneWay false SurfaceFriction 1.0 SurfaceForce 0.0";

P.O. the actor do collide with the object but it does not react as a PlatformBehavoir, like a Scene Object. It does not do the actorlanded nor the onground so it will not jump or run. It stays on air as before.

M.P. the PlatformBehavior from the PSK does the onAddToScene is this the same?

www.ingenpr.com/images/OnAir.png
#4
10/30/2008 (1:20 am)
Edwin, ouch!

The PSK has not really been set up to handle *that* kind of setup! If you wanted to, you could email me the project and I could take a quick look at it for you. I cannot promise that I can make the painted lines work as well as the regular platforms, but I can do my best.
#5
11/03/2008 (2:08 pm)
Thanks Edwin, I will try to find time to look at it later in the week.
#6
11/05/2008 (2:17 am)
Edwin, the problem here stems from the fact that the PSK uses gradients on single, not multiple, platforms. There are two ways you could tackle this, change the slope code, or create the ground in intervals (this one is hard to explain).

Neither of these tasks are going to be particularly easy to do, but I can't really think of a quick fix to help you in this circumstance.