It looks like you're new here. If you want to get involved, click one of these buttons!
-- set constants local lineTable = {} local lineWidth = 12 local lineColor = 0x0a8eea local lineBitmap = nil -- set up sprite groups local canvas = Sprite.new() self:addChild(canvas) local bitmapGroup = Sprite.new() canvas:addChild(bitmapGroup) local lineGroup = Sprite.new() canvas:addChild(lineGroup) -- draw line function local newLine = function(event) local function drawLine() local line = Shape.new() line:setLineStyle(lineWidth, lineColor, 1) line:beginPath() line:moveTo(linePoints[#linePoints-1].x, linePoints[#linePoints-1].y) line:lineTo(linePoints[#linePoints].x, linePoints[#linePoints].y) line:endPath() lineTable[i]:addChild(line) end if event:getType() == "mouseDown" then i = #lineTable+1 lineTable[i] = Sprite.new() lineGroup:addChild(lineTable[i]) linePoints = nil linePoints = {}; local pt = {} pt.x = event.x; pt.y = event.y; table.insert(linePoints,pt); elseif event:getType() == "mouseMove" then local pt = {} pt.x = event.x; pt.y = event.y; if not (pt.x==linePoints[#linePoints].x and pt.y==linePoints[#linePoints].y) then table.insert(linePoints,pt) drawLine() end elseif event:getType() == "mouseUp" then if i >= 10 then local lineTexture = nil local lineMerge = nil local lineTexture = RenderTarget.new(cwidth, cheight) local lineMerge = Sprite.new() if lineBitmap then lineMerge:addChild(lineBitmap) end lineMerge:addChild(lineTable[1]) lineTexture:clear(0x000000,0) lineTexture:draw(lineMerge) if lineBitmap then lineMerge:removeChild(lineBitmap, true) lineBitmap:removeFromParent() lineBitmap = nil end lineMerge:removeChild(lineTable[1]) lineBitmap = Bitmap.new(lineTexture) bitmapGroup:addChild(lineBitmap) lineTexture = nil lineMerge = nil lineTable[1]:removeFromParent() table.remove(lineTable, 1) end i = nil end return true end -- add paint event listeners self:addEventListener("mouseDown", newLine) self:addEventListener("mouseUp", newLine) self:addEventListener("mouseMove", newLine) |
Comments
But still how about something like this:
http://www.amazon.com/gp/product/B009IVLQ6Y
Likes: ndoss
Fragmenter - animated loop machine and IKONOMIKON - the memory game
here is my code (the 8 coordinates needed are computed beforehand and sent to this function) - i do some rounding, but this is mostly as i store it later in a json file and this way the file is smaller; so you can skip that.
ps: in this code it seems that all segments are in one mesh (which is preferable, also doing an undo is quite easy this way, using self:resizeIndexArray), which is true for one 'frame', but because i make a new 'frame' for all frames of the animation, actually i have also many of these 'frames' (meshes), all with many 'segments' (triangles), and it still runs fast.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: uncleking
Fragmenter - animated loop machine and IKONOMIKON - the memory game