The Problem is:
I have a little Game, with a Background Image as main field. If I click
on this field, I get the x and y coordinate of the actual cursor
position. This Data is stored in an array. No Problem so far...
But later, on this field there should be several Units moving. But if
there is a Unit, I have to put a Bitmap ON the main field, (to show that
there is a Unit) but then I can't intercept clicks anymore.
So I wanted to ask if there is any possibility to fetch the clicks. I
thought of some invisible field "above" the other two. Is there
something I could use?
Once more for clarification:
Layer1: (ground) Backgrundimage (Fields for Units, etc...)
Layer2: (middle) Picture of the Units, etc...
Layer3 (on top) The invisible field that fetches my mouse klicks and
writes them into an array.
I hope some of you can help...
Thx in advance
Oliver Putz
P.S.: I use the Borland CBuilder 6
(TUnit Sender, int X,int Y)
based on the "unit"s Top, Left and the X, Y relative to the Top, Left of the
unit, get the background coords as,
BackX = Sender->Top + X;
BackY = Sender->Left + Y;
Of course, I am assuming that the Top, Left of the "unit" are relative to
the background.
Regards,
Ananth B.
"Oliver Putz" <Rippe...@web.de> wrote in message
news:b3kukr$l3f$02$1...@news.t-online.com...
It is just a piece of that Form. In the left there are buttons, on top
there are Labels, etc...
--
Those who give up a little freedom for a little security, will lose both
and deserve neither
Machtlos ist der, der Aufgibt
You have a TImage and if you click on the TImage you can get the
position in OnMouseDown() event as X an Y.
> But later, on this field there should be several Units moving.
Could you please speak in terms of actual components and properties ?
So not 'field' but 'Image'. What would be a 'Unit' ?
> there is a Unit, I have to put a Bitmap ON the main field, (to show that
> there is a Unit) but then I can't intercept clicks anymore.
Show us how you place a bitmap on the Image that prevents clicking ?
> So I wanted to ask if there is any possibility to fetch the clicks. I
> thought of some invisible field "above" the other two. Is there
> something I could use?
You could -at designtime- place a TBevel above your TImage.
A TBevel cannot catch the OnMouseDown event as it is, but the following
code will give the clicks to the TImage OnMousDown eventhandler:
class TMyBevel : TBevel
{
public:
__property OnMouseDown;
};
__fastcall TForm2::TForm2(TComponent* Owner)
: TForm(Owner)
{
((TMyBevel*)Bevel1)->OnMouseDown = Image1MouseDown;
}
void __fastcall TForm2::Image1MouseDown(TObject *Sender,
TMouseButton Button, TShiftState Shift, int X, int Y)
{
ShowMessage ( "Image1MouseDown() X: "
+ IntToStr ( X )
+ " Y:" + IntToStr ( Y ) );
}
Hans.
>> But later, on this field there should be several Units moving.
>
>
> Could you please speak in terms of actual components and properties ?
>
> So not 'field' but 'Image'. What would be a 'Unit' ?
>
Ok, I used the wrong terms. The game is some sort of strategy game, so
what I called "units" are tanks, etc. But what actually is on the image
is a bitmap.
>> there is a Unit, I have to put a Bitmap ON the main field, (to show
>> that there is a Unit) but then I can't intercept clicks anymore.
>
>
> Show us how you place a bitmap on the Image that prevents clicking ?
>
Hm, ok, first of all I place the Background Image. But that is just the
"Landscape". Then on this Landscape there has to be a tank. So I want to
place the Bitmap of a tank "into" this Landscape. So if I have a 30x30
pixel Image, and a Tank is a 10x10 pixel Image, the 10x10 Image is put
in the upper left corner of the original bitmap. Now I can klick in the
upper Left corner, but The Landscape Image cant intercept the klick any
more, because I don't klick on the Landscape Image, but on the Tank
Image that is one level "above" (like two pictures: One is covering or
hiding the other.)
>> So I wanted to ask if there is any possibility to fetch the clicks. I
>> thought of some invisible field "above" the other two. Is there
>> something I could use?
>
>
> You could -at designtime- place a TBevel above your TImage.
>
> A TBevel cannot catch the OnMouseDown event as it is, but the following
> code will give the clicks to the TImage OnMousDown eventhandler:
>
> class TMyBevel : TBevel
> {
> public:
> __property OnMouseDown;
> };
>
>
> __fastcall TForm2::TForm2(TComponent* Owner)
> : TForm(Owner)
> {
> ((TMyBevel*)Bevel1)->OnMouseDown = Image1MouseDown;
> }
>
>
> void __fastcall TForm2::Image1MouseDown(TObject *Sender,
> TMouseButton Button, TShiftState Shift, int X, int Y)
> {
> ShowMessage ( "Image1MouseDown() X: "
> + IntToStr ( X )
> + " Y:" + IntToStr ( Y ) );
> }
>
> Hans.
>
>
Thanks, I'll try that.
PS : I also mixed up X and Y in there. So the correct code would be.
BackX = Sender->Left + X;
BackY = Sender->Top + Y;
Regards,
Ananth B.
"Oliver Putz" <Rippe...@web.de> wrote in message
news:b3l0hs$to5$00$1...@news.t-online.com...
> You could -at designtime- place a TBevel above your TImage.
>
> A TBevel cannot catch the OnMouseDown event as it is, but the following
> code will give the clicks to the TImage OnMousDown eventhandler:
>
> class TMyBevel : TBevel
> {
> public:
> __property OnMouseDown;
> };
>
>
> __fastcall TForm2::TForm2(TComponent* Owner)
> : TForm(Owner)
> {
> ((TMyBevel*)Bevel1)->OnMouseDown = Image1MouseDown;
> }
>
>
> void __fastcall TForm2::Image1MouseDown(TObject *Sender,
> TMouseButton Button, TShiftState Shift, int X, int Y)
> {
> ShowMessage ( "Image1MouseDown() X: "
> + IntToStr ( X )
> + " Y:" + IntToStr ( Y ) );
> }
>
> Hans.
>
>
Ok, I just gave it a try, and it seems to work flawlessly!
Thanks a lot!!!
> So if I have a 30x30
> pixel Image, and a Tank is a 10x10 pixel Image, the 10x10 Image is put
> in the upper left corner of the original bitmap. Now I can klick in the
> upper Left corner, but The Landscape Image cant intercept the klick any
> more, because I don't klick on the Landscape Image, but on the Tank
> Image
Yes, so you have the OnMouseDown() of the tanksTImage whick you can pass
to the OnMouseDown() of the background image.
I think the soluton offered by Ananth B. is very suitable for you.
Hans.
P.S. Please stop your over \quoting. Only leave a couple of lines
please.