Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Saving a shape into file — Gideros Forum

Saving a shape into file

ExCxExCx Member
edited December 2012 in General questions
Hi, I'm working on a drawing game app and thus I need to save the shape drawn by the user (not into an image file, it will probably be needed in the future though). I mean, it should be "loadable" afterwards.

I thought of a way that I can save the x, y coordinates of the each colored pixel into a table stored in a file. But I'm not really sure if that is an effecient way to reach my goal. Any ideas on that?
Tagged:

Comments

  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Copied from https://github.com/ar2rsawseen/GiderosCodingEasy
    Shape._new = Shape.new
     
    function Shape.new()
    	local shape = Shape._new()
    	shape._lastPoint = nil
    	shape._allPoints = {}
    	return shape
    end
     
    Shape._moveTo = Shape.moveTo
     
    function Shape:moveTo(x,y)
    	self:_moveTo(x, y)
    	self._lastPoint = { x, y }
    	self._allPoints[#self._allPoints+1] = x
    	self._allPoints[#self._allPoints+1] = y
    	return self
    end
     
    Shape._lineTo = Shape.lineTo
     
    function Shape:lineTo(x,y)
    	self:_lineTo(x, y)
    	self._lastPoint = { x, y }
    	self._allPoints[#self._allPoints+1] = x
    	self._allPoints[#self._allPoints+1] = y
    	return self
    end
     
    Shape._clear = Shape.clear
     
    function Shape:clear()
    	self:_clear()
    	self._allPoints = {}
    	return self
    end
     
    function Shape:getPoints()
    	return self._allPoints
    end
    Basically it stores all the points internally and provide new method for the Shape object - getPoints to return table with all the points in shape

    You can either create init.lua file and copy the code into it,
    or simply use GiderosCodingEasy with some other additional features

    http://www.giderosmobile.com/forum/discussion/1780/extending-gideros/p1

    Likes: ExCx

    +1 -1 (+1 / -0 )Share on Facebook
  • Always on time @ar2rsawseen, thank you very much. :)
Sign In or Register to comment.