Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have really throughly searched the net and could not find any solution for this so I ask for help here.

Anyway, I have this datablock in datablocks.cs:

    datablock t2dSceneObjectDatablock(EnemyShipConfig)  
{  
   canSaveDynamicFields = "1";  
   Layer = "3";  
   size = "64 64";  
   CollisionActiveSend = "1";  
   CollisionActiveReceive = "1";  
   CollisionCallback = true;  
   CollisionLayers = "3";  
   CollisionDetectionMode = "POLYGON";  
   CollisionPolyList = "0.00 -0.791 0.756 0.751 -0.746 0.732";     
   UsesPhysics = "0";  
   Rotation = "-90";  
   WorldLimitMode = "KILL";  
   WorldLimitMax = "880 360";  
   WorldLimitMin = "-765 -436";  

   minFireRate = "2000";  
   maxFireRate = "1200";  
   laserSpeed  = "800";  
   minSpeed    = "100";  
   maxSpeed    = "150";  
};  

This is an exact reproduction of an object that I have manually edited in the editor. So far, I just used clone() to get as many enemies as I need, while it was out of sight. It is a r-type style shooter, so I need a variable amount of enemies. Since clone() spams my log, I decided to use datablocks, since it is also more flexible.

That's what I get when I use clone():

Con::execute - 0 has no namespace: onRemoveFromScene

However, once spawning begins, my game freezes and crashes:

    function SpawnEnemy()  
{  
    //%spawnedEnemy = EnemyShipMaster.clone(true);  
    %spawnedEnemy = new t2dStaticSprite()  
    {  
       class         = "EnemyShip";  
       sceneGraph    = $global_sceneGraph;  
       datablock     = "EnemyShipConfig";    
       imageMap      = "starshipImageMap";  
       layer = 3;  
    };  

    %speed  = getRandom(%spawnedEnemy.minSpeed, %spawnedEnemy.maxSpeed);  
    %y      = getRandom(-320, 320);  

    // Set Properties  
    %spawnedEnemy.setPositionX(700);  
    %spawnedEnemy.setPositionY(%y);  
    %spawnedEnemy.setVisible(true);  
    %spawnedEnemy.setLinearVelocityX( -%speed );          
    %spawnedEnemy.setTimerOn( getRandom( %spawnedEnemy.maxFireRate, %spawnedEnemy.minFireRate ) );  
}  

// Definition of $global_sceneGraph from game.cs:  
$global_sceneGraph = sceneWindow2D.loadLevel(%level);  

As I said, it works fine when I use clone() (which is commented out here), but my log gets spammed. I really hope someone can shed some light for me, this is driving me crazy.

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I found out what caused it:

First of all, in the documentation it says that you need the datablock with the Keyword "datablock". In a different place on the same page in the documentation it says you need to use "dataBlock".

The real and correct keyword is "config".

The following changed code works:

datablock t2dSceneObjectDatablock(EnemyShipConfig)
{
   canSaveDynamicFields = "1";
   Layer = "3";
   size = "64 64";
   CollisionActiveSend = "1";   
   CollisionActiveReceive = "1";
   CollisionPhysicsReceive = "0";
   CollisionPhysicsSend = "0";
   CollisionCallback = true;
   CollisionLayers = "3";
   CollisionDetectionMode = "POLYGON";
   CollisionPolyList = "0.00 -0.791 0.756 0.751 -0.746 0.732";   
   UsesPhysics = "0";
   Mass = "0";
   Rotation = "-90";
   WorldLimitMode = "KILL";
   WorldLimitMax = "880 360";
   WorldLimitMin = "-765 -436";

   minFireRate = "2000";
   maxFireRate = "1200";
   laserSpeed  = "800";
   minSpeed    = "100";
   maxSpeed    = "150";
};

function SpawnEnemy()
{
    %spawnedEnemy = new t2dStaticSprite(EnemyShip)
    {
       sceneGraph    = $global_sceneGraph;
       config        = "EnemyShipConfig";
       imageMap      = "starshipImageMap";
    };  
    %speed  = getRandom(%spawnedEnemy.minSpeed, %spawnedEnemy.maxSpeed);
    %y      = getRandom(-320, 320);

    // Set Properties
    %spawnedEnemy.setPositionX(700);
    %spawnedEnemy.setPositionY(%y);
    %spawnedEnemy.setVisible(true);
    %spawnedEnemy.setLinearVelocityX( -%speed );
    %spawnedEnemy.setTimerOn( getRandom( %spawnedEnemy.maxFireRate, %spawnedEnemy.minFireRate ) );
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.