Monday, 9 April 2012

Object List - Dragging Objects

Here is the overall pointer handling routine with all the loops present and the code we have so far.
Moving the object (within the elseifGetPointerState() > 0 loop) is the easiest part, so we'll get that out of the way first.

The first thing we need to know is if an object was picked up, which will be indicated by the variable thisObjectPicked being greater than zero.  If not, then something else will happen - but we'll come back to that.

We calculate the new position of the object by subtracting the offsets we got when the object was picked up from the Pointer world position (or adding if you did it the other way), the results are then stored in temporary variables thisX# and thisY# for ease of reading.

The sprite is moved to the new position using the setSpritePositionByOffset().

We also set the depth of the sprite to be above the Panel - in case it is dragged over the panel.

The complete code looks like this.

   if thisObjectPicked > 0
      thisX# = PointWX() - thisPickOffsetX#
      thisY# = PointWY() - thisPickOffsetY#
      setSpritePositionByOffset( thisSpritePicked , thisX# , thisY# )
      setSpriteDepth( thisSpritePicked , DEPTH_PANEL - 5 )
   endif

How easy was that?

The pointer loops now look like this.
You can compile and run this to see the effect so far.
  Though bear in mind we don't have a routine to drop it down properly so its still not finished.

No comments:

Post a Comment