Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
How do I make something grow then shrink (problem with alignment) — Gideros Forum

How do I make something grow then shrink (problem with alignment)

Tom2012Tom2012 Guru
edited September 2012 in General questions
Hi,

I'm trying to make a button grow out and in a bit. I see how to use the enterFrame event to do it, but the alignment is taken from the top left of the button object.

Is there a way to set an objects reference point to say the center so it will scale in and out correctly?

Thanks



-- onEnterFrame

local scale = 1;

local function onEnterFrame ()

-- Make play button grow

scale = scale + .05;

playButton:setScaleY(scale);
playButton:setScaleX(scale);


end

stage:addEventListener(Event.ENTER_FRAME, onEnterFrame);

Comments

  • petecpetec Member
    Accepted Answer
    playButton:setAnchorPoint(0.5,0.5) should do it.
    For info - setAnchorPoint(0,0) is top left and setAnchorPoint(1,1) is bottom right
  • Would this be a good place for Gtween?
  • It could well be. This is what I've used to make buttons pulse. I started with something that set the scale instantly at the start so that it felt responsive and then used a tween to reset the scale to 1:
    function Sprite:pulse()
    	self:setScale(1.2)
    	GTween.new(self, 0.15, {scaleX=1,scaleY=1}, {})
    end
    By mistake I only entered one value in the setScale bit and found that it scaled both x and y like that. Is that a known feature? It's nice and easy to use as
    button:pulse()
    Then I developed it a bit so that I could enter a vale for the scaling, including one that is less than 1 so that I could make the sprite smaller if I wanted to, say when I want a button to look like its been pressed down or into something.
    function Sprite:pulse(scl)
    	self:setScale(scl)
    	GTween.new(self, 0.15, {scaleX=1,scaleY=1}, {})
    end
    Then I added a default scale factor so that I didn't have to always include a value:
    function Sprite:pulse(scl)
    	if scl == nil then
    		self:setScale(1.2)
    	else
    		self:setScale(scl)
    	end
    	GTween.new(self, 0.15, {scaleX=1,scaleY=1}, {})
    end
    And my final version came about because I used the pulse on something that I had already scaled down which caused a problem when the scale was set back to 1 by the tween. So the version I use now gets the original scale of the sprite and the tween resets it to that value rather than 1:
    function Sprite:pulse(scl)
    	local sclX=self:getScaleX()
    	local sclY=self:getScaleY()
    	if scl == nil then
    		self:setScale(sclX*1.2)
    	else
    		self:setScale(sclX*scl)
    	end
    	GTween.new(self, 0.15, {scaleX=sclX,scaleY=sclY}, {})
    end
    I've shown all the stages that I went through in case it's useful for anyone. I know when I first got started with Gideros something like my final version made much less sense than my first version :)
Sign In or Register to comment.