Project X Forums



It is currently Fri Mar 29, 2024 8:43 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: SetSpriteOverride - need help
PostPosted: Mon Apr 09, 2012 1:50 pm 
Offline
User avatar

Joined: Sun Apr 08, 2012 1:09 pm
Posts: 425
Location: Ukraine, Kyiv
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?!

_________________
Things to impress.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Skin by Lucas Kane