当前位置: 首页>>代码示例>>C++>>正文


C++ GameObject::FinalizeNodes方法代码示例

本文整理汇总了C++中GameObject::FinalizeNodes方法的典型用法代码示例。如果您正苦于以下问题:C++ GameObject::FinalizeNodes方法的具体用法?C++ GameObject::FinalizeNodes怎么用?C++ GameObject::FinalizeNodes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GameObject的用法示例。


在下文中一共展示了GameObject::FinalizeNodes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SpawnGameObjectEvent

//---------------------------------------
void Map::SpawnGameObjectEvent( Dictionary& params )
{
    std::string name;
    Vec2f position;

    // Get name
    if ( params.Get( "ObjectName", name ) != Dictionary::DErr_SUCCESS )
    {
        ConsolePrintf( CONSOLE_ERROR, "Failed to spawn GameObject: missing ObjectName\n" );
        return;
    }

    // Get position
    if ( params.Get( "Position", position ) != Dictionary::DErr_SUCCESS )
    {
        ConsolePrintf( CONSOLE_ERROR, "Failed to spawn GameObject: missing Position\n" );
        return;
    }

    // Spawn entity
    GameObject* gameObject = NULL;

    GameObjectDefinition* def = GameObjectDefinition::GetDefinitionByName( name );
    if ( def )
    {
        gameObject = def->Create();
        gameObject->Position = position;
        gameObject->GameMap = this;
        gameObject->SetBoundsFromSprite();
        gameObject->ObjectId = mObjects.size();

        // Call OnCreate for all logic nodes on the object
        gameObject->FinalizeNodes();

        mObjects.push_back( gameObject );
    }
    else
    {
        ConsolePrintf( CONSOLE_ERROR, "Failed to spawn GameObject: No GameObject found '%s'\n", name.c_str() );
    }
    params.Set( "GameObject", gameObject );
}
开发者ID:hydraskillz,项目名称:Mage2D,代码行数:43,代码来源:Map.cpp

示例2: LoadObjectGroup

//---------------------------------------
void Map::LoadObjectGroup( const XmlReader::XmlReaderIterator& itr )
{
    ObjLayer* layer = new ObjLayer;
    layer->Type = LT_OBJ;

    LoadLayerBaseInfo( layer, itr );

    for ( XmlReader::XmlReaderIterator objItr = itr.NextChild( "object" );
            objItr.IsValid(); objItr = objItr.NextSibling( "object" ) )
    {
        objItr.ValidateXMLAttributes( "x,y","name,width,height,type,visible" );

        std::string name = objItr.GetAttributeAsString( "name", "" );
        std::string type = objItr.GetAttributeAsString( "type", "" );
        int x = objItr.GetAttributeAsInt( "x" );
        int y = objItr.GetAttributeAsInt( "y" );
        int w = objItr.GetAttributeAsInt( "width", 0 );
        int h = objItr.GetAttributeAsInt( "height", 0 );
        bool visible = objItr.GetAttributeAsInt( "visible", 1 ) == 0 ? false : true;

        GameObject* gameObject;
        GameObjectDefinition* def = GameObjectDefinition::GetDefinitionByName( type );
        if ( def )
        {
            gameObject = def->Create();

            // Set attributes
            gameObject->Visible = layer->Visible;//visible;
            gameObject->Position.x = (float) x;
            gameObject->Position.y = (float) y;
            gameObject->BoundingRect.Set( x, y, x + w, y + h );
            gameObject->GameMap = this;
            gameObject->ObjectId = mObjects.size();

            // Load editor values for properties
            XmlReader::XmlReaderIterator propItr = objItr.NextChild( "properties" );
            if ( propItr.IsValid() )
            {
                LoadProperties( gameObject, propItr );
            }

            // Call OnCreate for all logic nodes on the object
            gameObject->FinalizeNodes();
        }
        else
        {
            ConsolePrintf( CONSOLE_WARNING, "Unknown object type: '%s'\n", type.c_str() );
            continue;
        }

        layer->Objs.push_back( gameObject );
        mObjects.push_back( gameObject );

        /*
        MapObject* mapObject = new MapObject(
        	name, type, RectI( x, y, x + w, y + h ), visible );

        // Read properties
        XmlReader::XmlReaderIterator propItr = objItr.NextChild( "properties" );
        if ( propItr.IsValid() )
        {
        	LoadProperties( mapObject->Properties, propItr );
        	mapObject->EvalProperties();
        }

        // Check for polyline
        XmlReader::XmlReaderIterator polylineItr = objItr.NextChild( "polyline" );
        if ( polylineItr.IsValid() )
        {
        	polylineItr.ValidateXMLAttributes( "points","" );

        	std::string pointCSV = polylineItr.GetAttributeAsString( "points" );
        	std::vector< std::string > csvTokens;
        	std::vector< std::string > csvTokenElements;
        	StringUtil::Tokenize( pointCSV, csvTokens, " " );
        	int xmin=0, xmax=0, ymin=0, ymax=0;
        	for ( auto csvItr = csvTokens.begin(); csvItr != csvTokens.end(); ++csvItr )
        	{
        		StringUtil::Tokenize( *csvItr, csvTokenElements, "," );

        		if ( csvTokenElements.size() == 2U )
        		{
        			int vx, vy;

        			if ( StringUtil::StringToType( csvTokenElements[0], &vx ) &&
        				 StringUtil::StringToType( csvTokenElements[1], &vy ) )
        			{
        				mapObject->Verticies.push_back( Vec2i( vx, vy ) );

        				if ( vx > xmax ) xmax = vx;
        				if ( vx < xmin ) xmin = vx;
        				if ( vy > ymax ) ymax = vy;
        				if ( vy < ymin ) ymin = vy;
        			}
        		}

        		csvTokenElements.clear();
        	}

//.........这里部分代码省略.........
开发者ID:hydraskillz,项目名称:Mage2D,代码行数:101,代码来源:Map.cpp


注:本文中的GameObject::FinalizeNodes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。