Game Development Community

Add image on Box2dCreateRectanglePoly

by Vados · in Torque Game Builder · 10/17/2011 (6:31 am) · 2 replies

Tell me, please how add image to bridge sigment.



if (!isObject(Bridge))
{
   %template = new BehaviorTemplate(Bridge);
   
    %template.friendlyName = "Bridge";
    %template.behaviorType = "Box2D";
    %template.description  = "";

    %template.addBehaviorField(x, "mount to (X)", float, 0);
    %template.addBehaviorField(y, "mount to (Y)", float, 0);
    
    %template.addBehaviorField(object, "The object to find", object, "", t2dSceneObject);
}
function Bridge::onLevelLoaded( %this, %sceneGraph )
{
   %this.setupScene(%sceneGraph);
}
function Bridge::setupScene(%this, %sceneGraph ) //sceneWindow2D
{

    %groundSceneObject = Box2dCreateRectanglePoly( "1 1" );
    %groundSceneObject.setPosition( "0 0" );
    %groundSceneObject.addBehavior( Box2dBodyBehavior.createInstance() );
    %groundSceneObject.addBehavior( Box2dShapeBehavior.createInstance() );

    %sceneGraph.worldRef.createBody( %groundSceneObject );
    %groundSceneObject.bodyRef.createShape( %groundSceneObject );
    ////////////
    %numPlanks = 30;

    %prevBody = %groundSceneObject.bodyRef;
    
    %jd = new t2dStaticSprite();

    %jd.jointType = e_revoluteJoint;
    
    for ( %i = 0; %i < %numPlanks; %i++ ) //setImageMap(segmentImageMap,0);
    {
        %plankSceneObject = %this.createPlank();
        %plankSceneObject.SetPosition( ( -14.5 + %i ) SPC -5 );
  
        %sceneGraph.worldRef.createBody( %plankSceneObject );        
        %plankSceneObject.bodyRef.createShape( %plankSceneObject );
        %plankSceneObject.bodyRef.setMassFromShapes();        
        
        %anchor = ( -15.0 + %i ) SPC -5;

        %this.initJointDef( %jd, %prevBody, %plankSceneObject.bodyRef, %anchor );
        
        %sceneGraph.worldRef.createJoint( %jd );
        
        %prevBody = %plankSceneObject.bodyRef;
    }
    %anchor = ( -15 + %numPlanks ) SPC -5;
    %this.initJointDef( %jd, %prevBody, %groundSceneObject.bodyRef, %anchor );
    %sceneGraph.worldRef.createJoint( %jd );
    
    %jd.delete();
    echo(worck);
}

function Bridge::createPlank( %this )
{
   //%sceneObject = %this.owner;
   //%sceneObject.(segmentImageMap,0);
   
    %sceneObject = Box2dCreateRectanglePoly( "1 0.1" );
    
    %shapeBehavior = Box2dShapeBehavior.createInstance();
    %shapeBehavior.Density = 20;
    %shapeBehavior.Friction = 0.2;
    %sceneObject.addBehavior( Box2dBodyBehavior.createInstance() );
    %sceneObject.addBehavior( %shapeBehavior );

    return %sceneObject;
}


function Bridge::initJointDef( %this, %def, %prevBody, %body, %anchor )
{
   %def.body1 = %prevBody;
	%def.body2 = %body;
	%def.localAnchor1 = %prevBody.getLocalPoint( %anchor );
	%def.localAnchor2 = %body.getLocalPoint( %anchor );
	%def.referenceAngle = %body.getAngle() - %prevBody.getAngle();
}

#1
10/17/2011 (10:44 am)
@slim4266 - Could you please post using the account that owns a source code license? That will make it easier for us to answer your questions.
#2
10/18/2011 (12:20 am)
Michael, this is my second profile with license(slim4266).