Page 1 of 1
Saving player drawing to variable and using it later?
Posted: Fri Jan 16, 2015 11:28 pm
by kxait
Hey. I'm making a game (something new...) and I want the player to be able to draw his own player image. I know they can draw penises and other stuff like that but I want to give the player freedom, anyway. How can I get the player drawing to save to a variable (ImageData perhaps?) and then drawing it to the screen? Like a normal image? I know how to make a 2d array and then modify the different parts of the array to edit the picture, then draw it based on the array, but how can I save it to a variable and then use it like a normal image? Hope this isn't too too confusing. Thanks in advance!
Re: Saving player drawing to variable and using it later?
Posted: Sat Jan 17, 2015 1:11 am
by SimonLarsen
You can have the player draw to a
Canvas.
Then when you want to save the data to a file, you can get the ImageData from the canvas and save it to a file with the encode function:
Code: Select all
local data = canvas:getImageData()
data:encode("drawing.png")
You can then load this drawing as any other image like you need it.
Re: Saving player drawing to variable and using it later?
Posted: Sat Jan 17, 2015 2:09 am
by s-ol
kxait wrote:Hey. I'm making a game (something new...) and I want the player to be able to draw his own player image. I know they can draw penises and other stuff like that but I want to give the player freedom, anyway. How can I get the player drawing to save to a variable (ImageData perhaps?) and then drawing it to the screen? Like a normal image? I know how to make a 2d array and then modify the different parts of the array to edit the picture, then draw it based on the array, but how can I save it to a variable and then use it like a normal image? Hope this isn't too too confusing. Thanks in advance!
look up Canvas on the löve wiki