7
Vielen Dank Leute- mein Programm läuft jetzt mit folgendem Code super
#include <vcl.h>
#pragma hdrstop
#include "Unit1.h"
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
Thread *Insthread;
int speed=3;
boolean rechts=false;
boolean links=false;
Graphics::TBitmap * hintergrund = new Graphics::TBitmap;
Graphics::TBitmap * buffer = new Graphics::TBitmap;
Graphics::TBitmap * bild = new Graphics::TBitmap;
int posx=0;
int posy=450;
Thread * Thread1 = new Thread(true);
__fastcall Thread::Thread(bool CreateSuspended)
: TThread(CreateSuspended)
{
}
void __fastcall Thread::Execute()
{
buffer->Width=1000;
buffer->Height=1000;
while(!Terminated)
{
Synchronize(syncro);
Sleep(1);
}
}
void __fastcall Thread::syncro()
{
bild->Transparent=true;
bild->TransparentColor=bild->Canvas->Pixels[0][0];
buffer->Canvas->Draw(0,0,hintergrund);
buffer->Canvas->Draw(posx,posy,bild);
Form1->Canvas->Draw(0,0,buffer);
if(rechts==true)
{
posx=posx+speed;
}
if(links==true)
{
posx=posx-speed;
}
}
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
void __fastcall TForm1::FormActivate(TObject *Sender)
{
Insthread= Thread1;
Thread1->Resume();
Form1->Height = 600;
Form1->Width= 900;
hintergrund->LoadFromFile("bild2.bmp");
bild->LoadFromFile("bild.bmp");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyDown(TObject *Sender, WORD &Key,
TShiftState Shift)
{
Form1->Caption=Key;
if(Key==16)
{
speed=6;
}
else
{
speed=3;
}
if(Key==37)
{
rechts=false;
links=true;
}
if(Key==39)
{
rechts=true;
links=false;
}
if(rechts==true && links==false)
bild->LoadFromFile("bild3.bmp");
if(links==true && rechts == false)
bild->LoadFromFile("bild.bmp");
}
//---------------------------------------------------------------------------
void __fastcall TForm1::FormKeyUp(TObject *Sender, WORD &Key,
TShiftState Shift)
{
rechts=false;
links=false;
}
//---------------------------------------------------------------------------