Page 1 of 1
[EDITED]Quick question about the canvas example
Posted: Mon Dec 29, 2014 6:40 pm
by nice
Hello boys and girls!
I have a question(s) about the canvas example (see link below):
1.
Why does canvas appear again inside the parentheses?
2.
Code: Select all
love.graphics.setBlendMode('alpha')
What's this line of code used for? and why should someone use it?
I thank you for your time and happy new year!
And yes I have checked the wiki thoroughly.
https://www.love2d.org/wiki/canvas
[EDIT]
thanks for clearing it up for me but I now have some new questions.
I would make another thread about it but I think that the new questions I have are similar to each other.
1. A mentor of mine said that canvases draws it to an offscreen object (let's call it canvas object) and that got me thinking:
Does the canvas function work like like a layer in Photoshop?
You have this canvas object on the screen that you collect everything on and if you want you can erase it to start a new one.
(Let me know if you want me to clear it up what I mean with it)
2. I have played around with the example for a while and started to see some similarities with something:
Code: Select all
--Does this:
love.graphics.setCanvas(canvas)
love.graphics.setCanvas()
--work similar to:
function love.draw()
end
To clear it up:
does setCanvas(canvas) and setCanvas() work like a function within a function? like what I did in a example function love.draw() and end.
Am right? or am I way wrong?
Re: [QUESTION]Quick question about the canvas example
Posted: Mon Dec 29, 2014 7:25 pm
by s-ol
1.) canvas is a variable passed to the function known as love.graphics.setCanvas. if you do not understand that you need to read up on lua some more.
2.) Did you read the documentation for love.graphics.setBlendMode? It's explained there and in the links on that page.
Re: [QUESTION]Quick question about the canvas example
Posted: Mon Dec 29, 2014 7:37 pm
by nice
S0lll0s wrote:1.) canvas is a variable passed to the function known as love.graphics.setCanvas. if you do not understand that you need to read up on lua some more.
2.) Did you read the documentation for love.graphics.setBlendMode? It's explained there and in the links on that page.
1. I guess you're right that I need to read up on Lua, might as well order a book about it as I find reading on my laptop distracts me.
2. I did read it and I tried out the example and from what I understand is that you can draw a colour on screen and then you can change it so that you can make the colour darker or lighter, am I correct.
It might sound like kinda stupid questions but I just want more in depth knowledge on what it does and to me adding the word canvas within parentheses is to me unlogical unless I have a proper explanation to why it's there.
Re: [SOLVED]Quick question about the canvas example
Posted: Mon Dec 29, 2014 8:55 pm
by Evine
This example probably makes some more sense. applePie is now the name of the canvas.
Code: Select all
applePie = love.graphics.newCanvas(1920,1080)
love.graphics.setCanvas(applePie)
Re: [SOLVED]Quick question about the canvas example
Posted: Mon Dec 29, 2014 9:09 pm
by nice
Evine wrote:This example probably makes some more sense. applePie is now the name of the canvas.
Code: Select all
applePie = love.graphics.newCanvas(1920,1080)
love.graphics.setCanvas(applePie)
I think I understand it better now, you can name the function what you want but this:
needs to be inside for the function to work.
Am I right or completely off?
Re: [SOLVED]Quick question about the canvas example
Posted: Mon Dec 29, 2014 9:50 pm
by Evine
Best explained in code. (untested but i think it should work)
Code: Select all
function love.load()
applePie = love.graphics.newCanvas(1920,1080) -- Creates canvas
end
function love.draw()
--Draw to screen
love.graphics.setCanvas(applePie)
--Draw to canvas
love.graphics.setCanvas() -- setCanvas without arguments to go back to drawing to screen
--Draw to screen
end
Re: [SOLVED]Quick question about the canvas example
Posted: Tue Dec 30, 2014 11:42 am
by nice
Evine wrote:Best explained in code. (untested but i think it should work)
Code: Select all
function love.load()
applePie = love.graphics.newCanvas(1920,1080) -- Creates canvas
end
function love.draw()
--Draw to screen
love.graphics.setCanvas(applePie)
--Draw to canvas
love.graphics.setCanvas() -- setCanvas without arguments to go back to drawing to screen
--Draw to screen
end
I'll take a look at it, thanks!
Re: [SOLVED]Quick question about the canvas example
Posted: Tue Dec 30, 2014 1:24 pm
by s-ol
nice wrote:Evine wrote:This example probably makes some more sense. applePie is now the name of the canvas.
Code: Select all
applePie = love.graphics.newCanvas(1920,1080)
love.graphics.setCanvas(applePie)
I think I understand it better now, you can name the function what you want but this:
needs to be inside for the function to work.
Am I right or completely off?
You don't name The function. The function name is in front of the parenthesis, everything in between are the parameters.
Re: [SOLVED]Quick question about the canvas example
Posted: Tue Dec 30, 2014 2:17 pm
by zorg
S0lll0s wrote:
You don't name The function. The function name is in front of the parenthesis, everything in between are the parameters.
Quick correction
Code: Select all
applepie = love.graphics.newCanvas
does create a variable called "applepie" that in a way is an alternative name for the function, but
Code: Select all
applepie = love.graphics.newCanvas(<params>)
actually calls the function, and if it returns something, that will be put into applepie; a new canvas in this case.