Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
(UNIVERSAL) Sprite:setAnchorPoint(0.5, 0.5) — Gideros Forum

(UNIVERSAL) Sprite:setAnchorPoint(0.5, 0.5)

PlatypusPlatypus Member
edited October 2013 in Suggestions & requests
@Atilim, @Ar2rsawseen,

Please make
Sprite:setAnchorPoint(0.5, 0.5)
work in the next Gideros release.

Please, please, please.

In addition, could you make (0.5, 0.5) the DEFAULT anchor point of all objects? That would be wonderful.

These individual ones would be nice too:
Bitmap:setAnchorPoint(0.5, 0.5)
Shape:setAnchorPoint(0.5, 0.5)
Stage:setAnchorPoint(0.5, 0.5)
stage:setAnchorPoint(0.5, 0.5)
Thanks.
Kate's Catalogue of Travelling Theatre Centres :
Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.

Comments

  • PlatypusPlatypus Member
    edited October 2013
    P.S. If the stage was anchored at (0.5, 0.5) by default, Gideros' built-in application-scaling algorithms would no longer need to calculate and implement "translate", right?
    Kate's Catalogue of Travelling Theatre Centres :
    Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
    She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
  • ar2rsawseenar2rsawseen Maintainer
    edited October 2013
    Oh gosh, I really hope your kidding :D
    Changing such behavior would brake backwards compatibility with any existing app.

    Ok lets get it one by one:

    Changing default behavior, definitely not, because you know, it would break existing code.

    Why Sprite does not have anchor points?

    Because it does not have its own boundaries and expand on any added content changing its dimensions. Implementing anchor points to it would be inefficient and ambiguous. Should anchor point stick with specific position after Sprite changed its dimensions, or change it proportionally expanding? If you add something with negative offset, should Sprites 0;0 coordinate change, because its dimensions just expanded, but it did not move? And there are three more variations how anchor point could behave.
    Either way with native implementation you would have to stick with single behavior that we would need to define, but now you can provide any behavior you want by yourself.
    Best approach on achieving what you need
    Position elements inside a Sprite object with negative offsets, so internal 0;0 coordinate would always be positioned where you want your anchor point to be.
    If you want Sprite anchored to 0.5;0.5, you want to add Bitmap object to it, add it with half negative offset like this:
    local sprite = Sprite.new()
    stage:addChild(sprite)
     
    local bmp = Bitmap.new(texture)
    bmp:setPosition(-bmp:getWidth()/2, -bmp:getHeight()/2)
    sprite:addChild(bmp)
    and your sprite behaves like its 0.5, 0.5 anchored

    Why Shape does not have anchor points?

    Completely same explanation as with Sprite, even more so, Shape was specifically designed for you to control the anchor point your self, by drawing on internal coordinates. You can even easily specify anchor point completely out of the drawn shape. Providing internal anchor points would only collide with the implementation and create a really hard to understand mess in Shape positioning.
    Best approach on achieving what you need
    Drawing with negative offset. If you want to draw 100x100 shape with 0.5, 0.5 anchor point, do it like this:
    local size = 100
    local half = size/1
    local s = Shape.new()
    s:beginPath()
    s:moveTo(-half, -half)
    s:lineto(half, -half)
    s:lineTo(half, half)
    s:lineTo(-half, hall)
    s:closePath()
    s:endPath()

    Why Stage does not have anchor points?

    How do you even imagine that? That 0;0 coordinate is not in the left top corner but lets say in the middle of the screen?
    But changing Stage's anchor point again could depend and interpreted on many factors, like should logical dimensions or device dimensions used, how to behave in different scaling mode? How to deal with whitespaces/offsets/etc
    Best approach on achieving what you need
    If you want stage to behave like with 0.5;0.5 anchor point (at screen center), simply position its 0;0 coordinate there, like this:
    stage:setPosition(application:getContentWidth()/2, application:getContentHeight()/2)
    And it will have negative offsets up and on the left sides

    Hope that helps ;)
  • I feel like reading Mells's post. \:D/

    Likes: Platypus

    +1 -1 (+1 / -0 )Share on Facebook
  • PlatypusPlatypus Member
    edited October 2013
    I feel like reading Mells's post. \:D/
    Ha, ha! That's EXACTLY what I thought!

    @Ar2rsawseen, thank you for your comprehensive, well-formatted rebuttal. You Mellsed me good.*



    ===============
    * For the benefit of people who are studying English:

    "You [verb]ed me good" is a jovial expression that deliberately employs incorrect English grammar.

    If the expression employed correct grammar, the sentence would be:
    "You [verb]ed me well".

    "Good" is an adjective.
    "Well" is an adverb (instead of saying "goodly").
    Kate's Catalogue of Travelling Theatre Centres :
    Meet Kate. Grey is her favourite colour. Maths is her favourite subject. Decency is her favourite type of behaviour.
    She definitely does not like jewellery or modelling, but loves aeroplanes and other machines made of aluminium.
  • Haha, I was about to "love" the answer (great level of support by @ar2rsawseen) but I can't do it anymore, people would say that I have a too high opinion of myself.

    Likes: Platypus

    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
    +1 -1 (+1 / -0 )Share on Facebook
  • Yes you got me, I was inspired by lots of @Mells posts :)
Sign In or Register to comment.