Page 1 of 1

Problems With Central Scaling [SOLVED]

Posted: Tue Mar 15, 2011 12:17 pm
by Archiboldian C.
Sorry about whining at the forums again, but I'm having troubles with love.graphics.scale() scaling a circle while keeping the circle in the center.
Here's my code:

Code: Select all

if area == "ingame" then
		love.graphics.push()
		love.graphics.scale(scale)
		love.graphics.setColor(51, 204, 102, 255)
		love.graphics.setBlendMode("alpha")
		love.graphics.setColorMode("modulate")
		love.graphics.circle("fill", 640, 400, 500, 500)
end

love.graphics.pop()
love.graphics.draw(p, 0, 0)
It all works except I can't get the code right to keep the circle in the center while it centers. I know it's just a simple bit of mathematics, but I'm finding it really hard to figure out.
Thanks in advance. :crazy:
J

Re: Problems With Central Scaling

Posted: Tue Mar 15, 2011 1:11 pm
by vrld
Draw the circle at 0,0, scale it, then move it to the target position:

Code: Select all

love.graphics.push()
love.graphics.scale(scale)
love.graphics.translate(640,400)
love.graphics.circle("fill", 0, 0, 500, 64) -- you wont really need 500 segments
love.graphics.pop()
Or, even easier, scale it yourself:

Code: Select all

love.graphics.circle("fill", 640, 400, scale * 500, 64)
Also, in your code the love.graphics.pop() is outside of the if-branch, meaning you sometimes pop without pushing.

Re: Problems With Central Scaling

Posted: Tue Mar 15, 2011 3:04 pm
by EmmanuelOga
Here are some helpers I've been using:

Code: Select all

local LG = love.graphics

local scaleAround = function(x, y, scale)
  if scale and scale ~= 1 then
    LG.translate(x, y)
    LG.scale(scale)
    LG.translate(-x, -y)
  end
end

local rotateAround = function(x, y, angle)
  if angle and angle ~= 0 then
    LG.translate(x, y)
    LG.rotate(angle)
    LG.translate(-x, -y)
  end
end
And here is how you can use them:

http://pastie.org/1674669

Guess I could just add the .love here.
scaleAround.love
Scale Around a Point
(654 Bytes) Downloaded 154 times

Re: Problems With Central Scaling

Posted: Tue Mar 15, 2011 5:22 pm
by Archiboldian C.
EmmanuelOga's scaleAround function worked perfectly thanks.
Plus using a variable to shorten the amount of typing needed is an excellent idea and something I used to do in AS3 but had completely forgotten about since converting to Linux and looking for alternatives for a creative programming platform.
Also thanks to vrld for telling me about my excessive angles, I should've tested some lower amounts but 500 worked so I got lazy.
Thanks.
This forum is great, never usually get a response which doesn't demand that you search google even though you have or that just treats you like a piece of crap from forums. I guess it's because LOVE is still in alpha (I assume from the current 0.7.1 version number) and there's a small community of early adopters and the ideology of the forum is to welcome new users and not scare the shit out of them.
Surely that's the point of open sourcing things? Sharing knowledge? Isn't that the point of a forum? Haha.
J

Re: Problems With Central Scaling [SOLVED]

Posted: Tue Mar 15, 2011 5:46 pm
by bartbes
Wait.. we're here for a game engine? :O

On a somewhat more serious note, we are just some lazy people who procrastinate too much, we try to be nice to each other, and for those who do not obey these rules we keep some pitchforks around.

Re: Problems With Central Scaling [SOLVED]

Posted: Tue Mar 15, 2011 9:08 pm
by Archiboldian C.
Haha, excellent.

Re: Problems With Central Scaling [SOLVED]

Posted: Tue Mar 15, 2011 9:12 pm
by crow
bartbes wrote:Wait.. we're here for a game engine? :O

On a somewhat more serious note, we are a just some lazy people who procrastinate too much, we try to be nice to each other, and for those who do not obey these rules we keep some pitchforks around.
Hey are you stealing thoughts out of my head " we are a just some lazy people" hehe :) so far I loving this forum and mind the pun :neko:

Re: Problems With Central Scaling [SOLVED]

Posted: Thu Mar 17, 2011 6:56 pm
by Archiboldian C.
HAH LOVING I GET IT