Saving player drawing to variable and using it later?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
kxait
Prole
Posts: 11
Joined: Wed Sep 17, 2014 7:52 am

Saving player drawing to variable and using it later?

Post 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!
Hey.
User avatar
SimonLarsen
Party member
Posts: 100
Joined: Thu Mar 31, 2011 4:47 pm
Location: Denmark
Contact:

Re: Saving player drawing to variable and using it later?

Post 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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Saving player drawing to variable and using it later?

Post 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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 4 guests