Skip to content

Instantly share code, notes, and snippets.

@Omar-Gonzalez
Last active December 24, 2015 00:59
Show Gist options
  • Save Omar-Gonzalez/6720244 to your computer and use it in GitHub Desktop.
Save Omar-Gonzalez/6720244 to your computer and use it in GitHub Desktop.
Touch and Drag a Vector Line W/Titanium & lines.mod
//Import Lines Module
var lines = require('com.lines');
//Window:
var win = Ti.UI.createWindow({
backgroundColor:'black'
});
//First event listener TouchStart the Origin Point
win.addEventListener('touchstart',function(e){
attrib = {
color:'yellow',
touchEnable:true,
thickness:5
};
var startX = e.x;
var startY = e.y;
from = {x:startX,y:startY};
to = {x:0,y:0};
lineOne = lines.createLine(from,to,attrib);
});
//Second Listener TouchMove(drag) Endpoint
win.addEventListener('touchmove',function(e){
win.remove(lineOne);
var touchX = e.x;
var touchY = e.y;
to = {x:touchX,y:touchY};
lineOne = lines.createLine(from,to,attrib);
win.add(lineOne);
});
win.open();
@Omar-Gonzalez
Copy link
Author

Simple draw tool: touch for origin point, drag for endpoint.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment