You can use the Ms object to access anything related to the mouse. Most computer mouses have more than one button, which is why you need to indicate which button you’d like to query. The left button has an index of 0, the right button an index of 1. If the mouse wheel can also be pressed, it will have index 2. Here are some examples:
Ms.bp(0); // true if the left button was pressed in this frame
Ms.br(1); // true if the right button was released in this frame
Ms.b (0); // true as long as the left button is held down
Ms.bd(0); // true when a double click is detected in this frame
5
There is a subtle difference between Ms.bp() and Ms.b():
The next example will illustrate this difference:
Vec2 mouse1Pos;
Vec2 mouse2Pos;
void InitPre()
5{
EE_INIT();
}
bool Init()
10{
return true;
}
void Shut() {}
15
bool Update()
{
if(Kb.bp(KB_ESC)) return false;
20 if(Ms.bp(0)) {
mouse1Pos = Ms.pos();
}
if(Ms.b(1)) {
25 mouse2Pos = Ms.pos();
}
return true;
}
30
void Draw()
{
D.clear(BLACK);
mouse1Pos.draw(RED );
35 mouse2Pos.draw(GREEN);
}
The red dot will only update its position on the moment you press the left button. In contrast, the green point will update as long as the right button is pressed. While working on an application, you will often have to decide which approach is best for the action at hand.