Problems With Central Scaling [SOLVED]

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
Archiboldian C.
Prole
Posts: 10
Joined: Sun Mar 13, 2011 12:52 pm
Location: UK
Contact:

Problems With Central Scaling [SOLVED]

Post 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
Last edited by Archiboldian C. on Tue Mar 15, 2011 5:26 pm, edited 1 time in total.
User avatar
vrld
Party member
Posts: 917
Joined: Sun Apr 04, 2010 9:14 pm
Location: Germany
Contact:

Re: Problems With Central Scaling

Post 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.
I have come here to chew bubblegum and kick ass... and I'm all out of bubblegum.

hump | HC | SUIT | moonshine
User avatar
EmmanuelOga
Citizen
Posts: 56
Joined: Thu Apr 22, 2010 9:42 pm
Location: Buenos Aires, Argentina
Contact:

Re: Problems With Central Scaling

Post 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 129 times
--------------------------------------------------------------------------------------------------------
http://EmmanuelOga.com
User avatar
Archiboldian C.
Prole
Posts: 10
Joined: Sun Mar 13, 2011 12:52 pm
Location: UK
Contact:

Re: Problems With Central Scaling

Post 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
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Problems With Central Scaling [SOLVED]

Post 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.
Last edited by bartbes on Tue Mar 15, 2011 9:25 pm, edited 1 time in total.
Reason: Shouldn't start a new sentence halfway through my old one, grammar doesn't like it
User avatar
Archiboldian C.
Prole
Posts: 10
Joined: Sun Mar 13, 2011 12:52 pm
Location: UK
Contact:

Re: Problems With Central Scaling [SOLVED]

Post by Archiboldian C. »

Haha, excellent.
User avatar
crow
Party member
Posts: 186
Joined: Thu Feb 24, 2011 11:47 pm
Location: UK
Contact:

Re: Problems With Central Scaling [SOLVED]

Post 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:
Sir Kittenface
Möko IDE Codename (Erös) Returns Soon

I am dyslexic so if any of my replys confusing please just ask me to reword it as this will make things a lot easier for all parties lol.
User avatar
Archiboldian C.
Prole
Posts: 10
Joined: Sun Mar 13, 2011 12:52 pm
Location: UK
Contact:

Re: Problems With Central Scaling [SOLVED]

Post by Archiboldian C. »

HAH LOVING I GET IT
Post Reply

Who is online

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