Multi-Resolution Game Development With GameBuilder Studio Check it out!
NEW Version 0.9.7 has arrived! New Blazing Fast Particle Engine & More Game Actions. Check it out
Dragging & Dropping Objects With The Mouse
  • Dragging an object with the mouse is very easy. You just have to check for the Mouse Down and Mouse Moving conditions and use an expression to subtract the current object's position from the current mouse position. Here is the mouse drag expression:

     setPoint(Self.BasicSpatial.position.x - (Self.BasicSpatial.position.x - Game.Mouse.x), Self.BasicSpatial.position.y - (Self.BasicSpatial.position.y - Game.Mouse.y))

    You can use the setPoint method in an expression to set the position property on a Spatial component. Use a Constrain Property action to set the position property with the above expression. This will continuously update the position value as long as the dragging conditions are true. 

    **Note: replace the BasicSpatial part of the expression with whatever the name of your spatial component is.

    812 x 1032 - 89K