[EDITED]Quick question about the canvas example

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Post Reply
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

[EDITED]Quick question about the canvas example

Post by nice »

Hello boys and girls!
I have a question(s) about the canvas example (see link below):

1.

Code: Select all

love.graphics.setCanvas(canvas)
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?
Last edited by nice on Tue Dec 30, 2014 8:01 pm, edited 3 times in total.
:awesome: Have a good day! :ultraglee:
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: [QUESTION]Quick question about the canvas example

Post 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.

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
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [QUESTION]Quick question about the canvas example

Post 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.
:awesome: Have a good day! :ultraglee:
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: [SOLVED]Quick question about the canvas example

Post 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)
Artal, A .PSD loader: https://github.com/EvineDev/Artal
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [SOLVED]Quick question about the canvas example

Post 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:

Code: Select all

love.graphics.newCanvas
needs to be inside for the function to work.

Am I right or completely off?
:awesome: Have a good day! :ultraglee:
User avatar
Evine
Citizen
Posts: 72
Joined: Wed May 28, 2014 11:46 pm

Re: [SOLVED]Quick question about the canvas example

Post 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
Artal, A .PSD loader: https://github.com/EvineDev/Artal
User avatar
nice
Party member
Posts: 191
Joined: Sun Sep 15, 2013 12:17 am
Location: Sweden

Re: [SOLVED]Quick question about the canvas example

Post 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!
:awesome: Have a good day! :ultraglee:
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: [SOLVED]Quick question about the canvas example

Post 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:

Code: Select all

love.graphics.newCanvas
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.

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
User avatar
zorg
Party member
Posts: 3470
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: [SOLVED]Quick question about the canvas example

Post 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.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: No registered users and 9 guests