Page 1 of 1

Problem with x,y scaling

Posted: Sat Sep 10, 2016 1:49 pm
by ElmuKelmuZ
So, I have 4 pseudo-classes that I use here.

Vector2 which is essentially just an X and Y value.
UDim2 which has an X,Y scale as well as X,Y offset
Color3 which has r,g,b values
ImageLabel which has properties as such:
Image
UDim2 inner workings:
Image
Image

So I use these to draw an image on screen, however nothing gets drawn when I do this:
Image
The size and position I set to it are as follows:
Image
I print out image:getDimensions() and all the stuff I pass onto love.graphics.draw and get this:
Image

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 2:14 pm
by raidho36
What's the color value? It might have zero alpha. Also that's awful lot of calculations for something as simple as storing a coordinate.

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 2:16 pm
by 0x72
Your default Color3 is black (i.e. "multiply every color by 0 so it's all black whatever texture is used").

I've changed Color3.new so it defaults to white (lines 12-14) and it works great

Code: Select all

    col3.r = Clamp(r or 255, 0, 255)
    col3.g = Clamp(g or 255, 0, 255)
    col3.b = Clamp(b or 255, 0, 255)
White sounds like a better default, but of course you can just set it manually in ImageLabel.new

Code: Select all

    img.Color = col or Color3.new(255, 255, 255)

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 2:40 pm
by KayleMaster
Side question, what's your IDE/text editor or whatever they call it?

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 3:30 pm
by ElmuKelmuZ
KayleMaster wrote:Side question, what's your IDE/text editor or whatever they call it?
Visual Studio 2013, using the BabeLua "plugin"

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 3:32 pm
by ElmuKelmuZ
0x72 wrote:Your default Color3 is black (i.e. "multiply every color by 0 so it's all black whatever texture is used").

I've changed Color3.new so it defaults to white (lines 12-14) and it works great

Code: Select all

    col3.r = Clamp(r or 255, 0, 255)
    col3.g = Clamp(g or 255, 0, 255)
    col3.b = Clamp(b or 255, 0, 255)
White sounds like a better default, but of course you can just set it manually in ImageLabel.new

Code: Select all

    img.Color = col or Color3.new(255, 255, 255)
Ah, stupid mistake by me again :/

Thanks :P

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 3:43 pm
by ElmuKelmuZ
Also now that this is settled and my next question doesn't deserve it's own new thread,

Image

How do I tweak my equations so a size of UDim2.new(1, 0, 1, 0) stretches the image to the screens bounds

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 4:31 pm
by Tjakka5
The target scale can be calculated by doing targetSize / imageSize.
If your screen resolution is static it's pretty straight forward.
If not you should use the love.resize() callback to recalculate all the target scales.

Re: Problem with x,y scaling

Posted: Sat Sep 10, 2016 6:36 pm
by Positive07
sx = [wiki]love.graphics.getWidth[/wiki]()/[wiki](Image):getWidth[/wiki]()
sy = [wiki]love.graphics.getHeight[/wiki]()/[wiki](Image):getHeight[/wiki]()