Use mouse draw line in the 2D,how to do?

Above, that’s the bit that draws the line between the last point and the cursor. I’d gate it with a Branch controlled with a boolean set onMouseDown. When the left click goes down, set bool to True; when right clicks goes down, set it to false. That *should *do it.

Pretty much.

It looks just like a fake border to me ;p, just to demo things in context. The answer to this depends on how it’s supposed to work from the gameplay point of view. As in, what should happen when we exceed the allowed area? Do we draw part of the line, stop drawing this line, stop drawing altogether, draw a line at the edge, some other criteria…

There’s several things one could do.

  • constrain the cursor movement to widget area (may feel horrible to the player, can’t recommend it)
  • have onPaint respect coords calculated during onMouseMove by translating absolute screenspace to local widget geometry, yada, yada, yada; 2d vector math. Essentially, compare screensize to widget size and check if the mouse coords are within range. Have the check put up a flag that can be used elsewhere in the code.
  • or it might be enough to play dumb and do this:

We only get to paint if the mouse is over the widget; the bool controls the condition:

You will need to perform the same check when the mouse goes down and a coord is added (or not) to the array.
[HR][/HR]
Not sure how you’ve set it up so far but I’d probably start the whole thing by creating a user widget one can draw on and make it a part of the page. This way you can include it (even add it dynamically) to pages that need it and no longer need to worry about exceeding boundaries. This way you could read mouse position from the widget, rather than from the controller - which is not that sensible here to start with… :expressionless: