I think it would be nice to change some sprites while gameplay. like.. the t-cloud. But while making it i found some problems, which i cant solve.
As i understood, InitGraphic() works once, at the begining of the game. Is it possible to use SetSpriteOverride in some other way, to call it at any moment of the gameplay? Thats what i wonder to know.
Script below supposed to change sprite of tcloud to a variation of different. Sprite still should be loaded in usual "t" pressing way, but which sprite to show - we can choose by pressing keys around "t" key. for example pressing "E" once, then pressing "t" will show WTF-cloud (like on my avatar); "R" pressing once, then "t" pressing will show !-cloud; and "Y" pressing once, then "t" pressing should get back t-cloud sprite.
so here`s the script:
Code:
void customscheme::Init()
{
keySync->AddKey(69); // E button
keySync->AddKey(82); // R button
keySync->AddKey(89); // Y button
}
void customscheme::InitGraphic()
{
CFile *cloud;
cloud = GetAttachment("wcloud.png");
wcloud = LoadSprite(cloud, 29, 0);
cloud = GetAttachment("icloud.png");
icloud = LoadSprite(cloud, 29, 0);
cloud = GetAttachment("tcloud.png");
tcloud = LoadSprite(cloud, 29, 0);
}
void customscheme::FirstFrame()
{
c = 0;
}
override void CWorm::Message(CObject* sender,EMType Type,int MSize,CMessageData* MData)
{
super;
if(GetCurrentWorm() != NullObj)
{
if(GetCurrentWorm() == this)
{
if(Type == M_FRAME)
{
if(keySync->KeyPressedNow(69) == true)
{
c = 1;
changeSprite();
GG->WriteToChat(2, "You just pressed E key!", false);
}
if(keySync->KeyPressedNow(82) == true)
{
c = 2;
changeSprite();
GG->WriteToChat(2, "You just pressed R key!", false);
}
if(keySync->KeyPressedNow(89) == true)
{
c = 0;
changeSprite();
GG->WriteToChat(2, "You just pressed I key!", false);
}
}
}
}
}
void CWorm::changeSprite()
{
if (c == 1)
{
SetSpriteOverride(136, wcloud);
GG->WriteToChat(2, "function WTF-cloud executed", false);
}
if (c == 2)
{
SetSpriteOverride(136, icloud);
GG->WriteToChat(2, "function !-cloud executed", false);
}
if (c == 0)
{
SetSpriteOverride(136, tcloud);
GG->WriteToChat(2, "function t-cloud executed", false);
}
}
p.s. by getting those messages in chat like "You just pressed E key!" and "Function WTF-cloud executed" i can say that script works correctly, but SetSpriteOverride - doesnt. What i also found - if game starts and i press T - i see T-cloud. If game starts and i press E-key first, then T - i see WTF-cloud. Question:
WTF?!