Jump to content

A looped graphic refreshing function gets slower and slower

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
2 replies to this topic

#1
FenixEden

FenixEden

    Newbie

  • Members
  • Pip
  • 6 posts
So, I got problems when I click on a label.
The label object clicks call this

private: System::Void GoSouth_Click(System::Object^ sender, System::EventArgs^ e) {


if (WhereAim != "South") {
LeggingPath = "C:\\Images\\SQSSPants.png";
TorsoPath = "C:\\Images\\SQSSShirt.png";
HeadPath = "C:\\Images\\SQSSFace.png";
WeaponPath = "C:\\Images\\SQSSSword.png";
ShieldPath = "C:\\Images\\SQSSWoodShield.png";
WhereAim = "South";
}

int CharX2;
int CharY2;
CharY2 = CharY +25;
if (CharY2 > 300) {
CharY2 = 300;
}
RefreshMap(true);
while (CharY2 > CharY) {
RefreshMap(false);
CharY = CharY +1;
}

}
Then
RefreshMap calls this
void RefreshMap(bool IfWhole) {

if (IfWhole == true) {
SpriteImage->BackColor = Color::Black;
}
SpriteImage->Paint += gcnew System::Windows::Forms::PaintEventHandler( this, &MainPlay::SpriteImage_Paint );
SpriteImage->Refresh();
if (IfWhole == true) {
delete SpriteImage->Image;

}
}

wich in turns calls this :

void SpriteImage_Paint( Object^ /*sender*/, System::Windows::Forms::PaintEventArgs^ e)
{
e->Graphics->Clear(Color::Black);

if (WhereAim == "South") {
e->Graphics->DrawImage(Legging, CharX, CharY, Legging->Width, Legging->Height);
e->Graphics->DrawImage(Torso , CharX, CharY, Torso->Width , Torso->Height );
e->Graphics->DrawImage(Head , CharX, CharY, Head->Width , Head->Height );
e->Graphics->DrawImage(Weapon , CharX, CharY, Weapon->Width , Weapon->Height );
e->Graphics->DrawImage(Shield , CharX, CharY, Shield->Width , Shield->Height );
}

if (WhereAim == "North") {
e->Graphics->DrawImage(Weapon , CharX, CharY, Weapon->Width , Weapon->Height );
e->Graphics->DrawImage(Shield , CharX, CharY, Shield->Width , Shield->Height );
e->Graphics->DrawImage(Legging, CharX, CharY, Legging->Width, Legging->Height);
e->Graphics->DrawImage(Torso , CharX, CharY, Torso->Width , Torso->Height );
e->Graphics->DrawImage(Head , CharX, CharY, Head->Width , Head->Height );
}

}


===============================================

So
I wanna know why each time I click on my label the movement of my character gets slower and slower...
(Can't be more concised heh?

#2
Vswe

Vswe

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 9,552 posts
You add an event handler each time you call Refreshmap:

SpriteImage->Paint += gcnew System::Windows::Forms:aintEventHandler( this, &MainPlay::SpriteImage_Paint );

Therefore it updates your image first once then twice then trice etc. each time (this is what takes the time). You should instead put the above code in the load event or somewhere else where it just occur once.

#3
FenixEden

FenixEden

    Newbie

  • Members
  • Pip
  • 6 posts
So, How do I paint it more than once without paiting it twice than trice than 4x?
===EDIT===
....
Sorry...
Just understood that refresh did the job.
Thanks a lot