Fork me on GitHub

API / Math / Drag

Usage

re.e('image object.png drag mouse')
.on('mousedown', function(x, y){
	this.dragStart(x, y);
})
.on('mousemove', function(x, y){
	this.dragUpdate(x, y);
})
.on('mouseup', function(x, y){
	this.dragFinish();
});

//drag screen
re.screen.comp('mouse drag')
.on('mousedown', function(x, y){
       //make negative
	this.dragStart(-x, -y);
})
.on('mousemove', function(x, y){
	this.dragUpdate(-x, -y);
})
.on('mouseup', function(x, y){
	this.dragFinish();
});

Description

The Drag component is an easy solution to dragging a draw entity with the cursor. This can also be used to ease movement.

Defaults

  • .dragging = false

    The current dragging state of the entity. False means its not being dragged.

  • .dragX = 0

    Dragging delta x.

  • .dragY = 0

    Dragging delta y.

  • .posX = 0

    Default position x.

  • .posY = 0

    Default y position.

Defines

  • .dragFinish()

    Ends the drag phase.

  • .dragStart(x, y)

    Starts the dragging phase and sets the align values. The align values are using the x and y coordinates of where the user first clicked.

  • .dragUpdate(x, y)

    Updates the dragging delta and updates the posX and posY values.

Updated / added in version 0.3.1

Last Updated Mar 30, 2012