Создание Flash HUD

Материал из CryWiki Russia

(Различия между версиями)
Перейти к: навигация, поиск
(Новая страница: «= Flash HUD Creation = CryENGINE supports Scaleform GFx to load and render Flash assets within a game. To load a flash file follow the [http://freesdk.crydev.net/d...»)
Строка 1: Строка 1:
 +
{{в процессе перевода|дата=9 марта 2011}}
 +
= Flash HUD Creation =
= Flash HUD Creation =

Версия 12:10, 9 марта 2012

Эта страница страница помечена как находящиеся в процессе перевода с: 9 марта 2011.


Flash HUD Creation

CryENGINE supports Scaleform GFx to load and render Flash assets within a game.

To load a flash file follow the Scaleform GFx and CryENGINE document.

Calling a Flash function

In order to do this you have to write a global function in your Flash file:

ActionScript
setHealth = function(_intHitpointsPercent)
{
    // set text of a dynamic text box (don't forget to embed the charackter set)
    txtHealth.text = "Health: " + _intHitpointsPercent.toString();
}


and call this function within your c++ code:


C++
CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
if (pActor != NULL)
{
    int health = pActor->GetHealth();
    pFlashPlayer->Invoke1("setHealth", health);
}


There are three Invoke functions that allow you to call flash functions:


C++
pFlashPlayer->Invoke0( "flashFunction" ); // 0 arguments
pFlashPlayer->Invoke1( "flashFunction", arg1 ); // 1 arguments
 
SFlashVarValue args[3] = { arg1, arg2 , arg3 };
m_pFlashPlayer->Invoke( "setPlayerPos" , args , 3 ); // 2 or more arguments


Loading a Minimap

The Sandbox Editor has a function to create a minimap for your level. More information can be found in the Creating Mini Maps tutorial.

After you have created the .dds and .xml files of your level, you can easily load this .dds file into your flash hud.

You have to create a function in your Flash file that loads a file by a given filename into a MovieClip:

ActionScript
setMiniMap = function(_strPathToMiniMap)
{
    //_strPathToMiniMap:    scaleform compatible path to the background map image, should be .dds
    loadMovie("img://"+ _strPathToMiniMap, MiniMapMC);
}


now you can call this function by c++


C++
pFlashPlayer->Invoke1("setMiniMap", "Levels\\PacificIsland\\PacificIsland.dds");


You may want to show some dynamic items on the minimap, player position, for example.

To do this you have to read the .xml file that is created by the Sandbox Editor to get the start and end values of the minimap.


C++
float mapStartX = 0;
float mapStartY = 0;
float mapEndX = 1;
float mapEndY = 1;
 
IXmlParser* pxml = gEnv->pGame->GetIGameFramework()->GetISystem()->GetXmlUtils()->CreateXmlParser();
if(pxml != NULL)
{
    XmlNodeRef node = GetISystem()->LoadXmlFile("Levels\\PacificIsland\\PacificIsland.xml");
    if (node != NULL)
    {
        node = node->findChild("Minimap");
        if (node)
        {
            node->getAttr("startX", mapStartX);
            node->getAttr("startY", mapStartY);
            node->getAttr("endX", mapEndX);
            node->getAttr("endY", mapEndY);
        }
    }
}
 
float mapDimX = mapEndX - mapStartX;
float mapDimY = mapEndY - mapStartY;
// Note: you may check if the dimensions are not 0!


Now you can simply create position values between 0 and 1 and send them to Flash:


C++
CActor *pActor = static_cast<CActor *>(gEnv->pGame->GetIGameFramework()->GetClientActor());
if (pActor != NULL && pActor->GetEntity() != NULL)
{
    Vec3 pos = pActor->GetEntity()->GetWorldPos();
    float posx = (pos.x - mapStartX) / mapDimX; // value from 0 to 1
    float posy = (pos.y - mapStartY) / mapDimY;
    SFlashVarValue args[3] = { posx, posy , pActor->GetAngles().z *180.0f/gf_PI-90.0f}; // note that the minimap is rotated by -90 degree
    m_pFlashPlayer->Invoke("setPlayerPos", args, 3);
}


On the Flash side you can implement a function that sets position and rotation of a MovieClip that represents the player position on the minimap:

ActionScript
setPlayerPos = function(_floatPosx, _floatPosy, _intRot)
{
    // the created minimap .dds file has dimensions 512*512
    var pX = _floatPosy * 512; // since map is rotated about -90 degree, switch x and y coordiantes
    var pY = _floatPosx * 512;
 
    PlayerPosMC._x = pX;
    PlayerPosMC._y = pY;
 
    PlayerPosMC._rotation = -_intRot;
}