Basic Mouse Checker framework
Posted: Sun Nov 23, 2008 12:49 pm
This is a framework that checks if the mouse is inside a rectangle or a flipbook. It works at LowLevel, i am unsure if it works at HighLevel too.
Lets say you want to draw a flipbook at position (160,120) on the screen and want to check if the mouse is over it. The flipbook is 500 pixels wide and 300 pixels high. You would just write:
If you want to check quickly if the player pressed the left mousebutton while on the flipbook (e.g. you have button and the player clicks on it) then you would write:
I know this could also be accomplished with the CheckArea commands, but if find them difficult to use.
Hope this helps.![Wink :wink:](./images/smilies/icon_wink.gif)
Code: Select all
{
MouseIsInsideRectangle[ (left, top, right, bottom)
{
MOUSE_X=GetMousePosX();
MOUSE_Y=GetMousePosY();
if(MOUSE_X<left)
{
return 0;
}
if(MOUSE_X>right)
{
return 0;
}
if(MOUSE_Y<top)
{
return 0;
}
if(MOUSE_Y>bottom)
{
return 0;
}
return 1;
} ]
MouseIsInsideDrawnFlipbook[ (left, top, sizeX, sizeY)
{
return MouseIsInsideRectangle(left, top, left+sizeX, top+sizeY);
} ]
CheckEventWhileOnRectangle[ (left, top, right, bottom, event)
{
return (event and MouseIsInsideRectangle(left,top,right,bottom));
} ]
CheckEventWhileOnDrawnFlipbook[ (left, top, sizeX, sizeY, event)
{
return (event and MouseIsInsideDrawnFlipBook(left,top,sizeX,sizeY));
} ]
}
Code: Select all
DrawFlipBookImage(FLIPBOOK_NAME, FLIPBOOK_INDEX, 160, 120, 255, 255, 255, 255, 1 );
if(MouseIsInsideDrawnFlipbook(160, 120, 500, 300))
{
...
}
Code: Select all
DrawFlipBookImage(FLIPBOOK_NAME, FLIPBOOK_INDEX, 160, 120, 255, 255, 255, 255, 1 );
if(CheckEventWhileOnDrawnFlipbook(160, 120, 500, 300, self.lbutton_pressed))
{
...
}
Hope this helps.
![Wink :wink:](./images/smilies/icon_wink.gif)