Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Bitmap:setAnchorPoint or Sprite:setAnchorPosition — Gideros Forum

Bitmap:setAnchorPoint or Sprite:setAnchorPosition

What is the difference between the two methods Bitmap:setAnchorPoint or Sprite:setAnchorPosition? The former seems to offset the texture and the latter seems to offsets the origin of the sprite. What are the differences and more importantly what are the usages of those methods?
I kind of think both could be used to displace the origin of a sprite to make it rotate and scale around it but I don't see very well when to use one or the other.

Comments

  • olegoleg Member
    edited July 2018
    Sprite:setAnchorPoint = in percent (0-1)

    Sprite:setAnchorPosition = in pixels
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+2 / -0 )Share on Facebook
  • I use setAnchorPoint(0.5,0.5) very often :smile:

    Recently there was discussion of KnifeHit game mechanics, there is good example of using setAnchorPosition(in pixels), by @antix
    http://giderosmobile.com/forum/discussion/7355/knife-hit-mechanics-how-to
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • @2oleg you're very terse in your responses, no?
    @Apollo14 Thanks for your link but it's too high level for mine. I don't understand the discussion. I'm a beginner after all.
  • olegoleg Member
    @flashjaysan These are the consequences of using twitter ;)

    Likes: antix

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+1 / -0 )Share on Facebook
  • olegoleg Member
    Guys and how to anchor only one axis?
    setAnchorPointX(0.5)
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • Apollo14Apollo14 Member
    edited August 2019
    oleg said:

    Guys and how to anchor only one axis?
    setAnchorPointX(0.5)

    yourSprite:setAnchorPoint(0.5,0) --first value is X, second value is Y. They both =0 by default
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • olegoleg Member
    edited August 2019
    Apollo14 said:

    oleg said:

    Guys and how to anchor only one axis?
    setAnchorPointX(0.5)

    yourSprite:setAnchorPoint(0.5,0) --first value is X, second value is Y. They both =0 by default
    I need Y to not change,

    Even if I have an anchor of 0 and again putting 0 - the sprite updates its position, and I don't need it! -I need the sprite - did not change position.
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • hgy29hgy29 Maintainer
    edited August 2019
    oleg said:

    Guys and how to anchor only one axis?
    setAnchorPointX(0.5)

    Generally speaking, you can't do taht with setAnchorPoint, you'll have to use getAnchorPosition followed by setAnchorPosition, leaving the axis you don't want to change at its previously read value. Of course you'll need to compute the anchor position in pixels, multiplying the ratio width the sprite's width or height.

    As a particular case, you can do it with Bitmap, since it has a getAnchorPoint call.

    Likes: oleg

    +1 -1 (+1 / -0 )Share on Facebook
  • olegoleg Member
    hgy29 said:

    oleg said:

    Guys and how to anchor only one axis?
    setAnchorPointX(0.5)

    Generally speaking, you can't do taht with setAnchorPoint, you'll have to use getAnchorPosition followed by setAnchorPosition, leaving the axis you don't want to change at its previously read value. Of course you'll need to compute the anchor position in pixels, multiplying the ratio width the sprite's width or height.

    As a particular case, you can do it with Bitmap, since it has a getAnchorPoint call.
    I do exactly that, but I thought maybe there was another solution ..
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • it could be convenient if we could pass negative values :smiley:
    setAnchorPoint(-0.5,0)
    > Newcomers roadmap: from where to start learning Gideros
    "What one programmer can do in one month, two programmers can do in two months." - Fred Brooks
    “The more you do coding stuff, the better you get at it.” - Aristotle (322 BC)
  • olegoleg Member
    edited August 2019
    Apollo14 said:

    it could be convenient if we could pass negative values :smiley:

    setAnchorPoint(-0.5,0)
    Just the anchor will be outside the sprite on the left
    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
  • olegoleg Member
    I created my own function that correctly sets the anchor:
    function setAnchorPointX(sprite,x) --встановити якір тільки по одній осі
    	local x2,y=sprite:getAnchorPosition()
    	y=y/sprite:getHeight()
    	sprite:setAnchorPoint(x,y)
    end

    Likes: Apollo14, pie

    my games:
    https://play.google.com/store/apps/developer?id=razorback456
    мій блог по гідерос https://simartinfo.blogspot.com
    Слава Україні!
    +1 -1 (+2 / -0 )Share on Facebook
Sign In or Register to comment.