Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Scaling Question — Gideros Forum

Scaling Question

NinjadoodleNinjadoodle Member
edited October 2015 in General questions
Hi guys

I've set my sprites anchor point to (0.5, 0.5) and put it in the middle of the screen.
Prop = Core.class(Sprite)
 
function Prop:init(atlas, texture, x, y, container)
	local sprite = Bitmap.new(atlas:getTextureRegion(texture, true))
	sprite:setAnchorPoint(0.5, 0.5)
	sprite:setPosition(x, y)
	self:addChild(sprite)
    container:addChild(self)
end
When I try to scale the sprite down tho (inside the scene), it seems to be scaled into a corner of the screen.
function Scene1:onTransitionInBegin()
 
	createContainers(self)
 
	self.hole = Prop.new(self.pack, "splashHole.png", 160, 224, mg)
	self.hole:setScale(0.25, 0.25)
 
 
end
It works when I set scale within the class itself.

Am I doing something wrong?

Thank you in advance for any help!

Comments

  • keszeghkeszegh Member
    edited October 2015
    you scale the prop itself, and not the bitmap, so do it like this:
    self.hole.sprite:setScale(0.25, 0.25)
    it's a homework then to think over why scaling the prop will result in what you have seen (as it's the logical thing what happened).

    1. in general a bitmap i would call bitmap and not sprite, it's easier to keep track i guess
    2. i've seen somebody recommender using this container in the init, personally i think it's easier to keep track if you add the prop afterwards to the appropriate sprite, so leaving out container and the last line of init and adding after
    prop=Prop.new(a,t,x,y)
    parentSprite:addChild(prop)
    then in your main code you see that it's added and to which sprite. but that's a personal choice, i agree.
  • keszeghkeszegh Member
    Accepted Answer
    also you can do that you don't position your sprite, only your prop, that would again work:
    Prop = Core.class(Sprite)
     
    function Prop:init(atlas, texture, x, y, container)
    	local sprite = Bitmap.new(atlas:getTextureRegion(texture, true))
    	sprite:setAnchorPoint(0.5, 0.5)
            self:setPosition(x, y)
    	self:addChild(sprite)
        container:addChild(self)
    end
    and then the transitionin function of yours would work, i think.
  • NinjadoodleNinjadoodle Member
    edited October 2015
    Hi @keszegh

    I understand now how it all works. Thank you heaps for your help :)

    I'm using another engine as well at the moment, and thing work slightly differently.

    Thank you again!
Sign In or Register to comment.