Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Sprite and Anchor Point — Gideros Forum

Sprite and Anchor Point

seppseppseppsepp Member
edited March 2013 in General questions
Hey.

What are our chances to get anchor points to sprites? I arranged my scene using some sprites as containers for underlying sprites. Scaling the container scales children too. But scaling goes into the direction of the container sprites' left top corner - which apparently can't be changed. Anchor point seems to be a chance to get rid of this behaviour ;) .

Greetings

Sebastian

Likes: Platypus

+1 -1 (+1 / -0 )Share on Facebook

Comments

  • ar2rsawseenar2rsawseen Maintainer
    It seems that everyone now lives with their own anchorpoint implementation for sprites.

    For example @Niicodemus uses his own hack for dealing with scaling:
    http://www.giderosmobile.com/forum/discussion/2715/camera-class-with-kinetics-and-pinch-to-zoom#Item_7

    But there are some more general usage addons as GiderosCodingEasy:
    https://github.com/ar2rsawseen/GiderosCodingEasy

  • @ar2rsawseen thanks for your reply. And sorry for being a bit late with this reply. Problem with the Coding Easy lib: It crashes in the Gideros scene manager in line 253 and Coding Easy Lib line 125 with a stack overflow - endless recursion it seems.

    Stack trace:
    ...
    ./lib/sprite.lua:125: in function '?'
    ./lib/sprite.lua:125: in function '?'
    ./lib/sprite.lua:125: in function '?'
    ./lib/sprite.lua:125: in function '?'
    lib/sprite.lua:125: in function 'addEventListener'
    lib/scene_manager.lua:253: in function 'init'
    [string "property.lua"]:52: in function '__new'
    [string "property.lua"]:59: in function 'new'
    main.lua:4: in main chunk

    Files:
    https://github.com/ar2rsawseen/GiderosCodingEasy/blob/master/GiderosCodingEasy.lua
    https://github.com/gideros/Scene-Manager/blob/master/scenemanager.lua

    I'll have a closer look at it. Maybe the solution is more obvious to you than to me ;) ...


    Greetings
    Sebastian
  • I still have no clue. Anyone else?
  • ar2rsawseenar2rsawseen Maintainer
    edited March 2013
    It seems to be that it loops in constructor, but can't figure out why. Will experiment more ;)
    It does not happen every time, only in some specific situations, but I can't figure which now :)
  • ar2rsawseenar2rsawseen Maintainer
    edited March 2013
    Ok, scratch what I wrote before. GiderosCodingEasy seem to work fine :)

    Does your project work without GiderosCodingEasy?

    It seems that you can't add your scene as a child of SceneManager?
    Is your scene inherited from Sprite?

    As in like this:
    scene = Core.class(Sprite)
    And NOT like this:
    scene = Core.class()
  • seppseppseppsepp Member
    edited March 2013
    Yes, the scene inherits from Sprite =| .

    Yes, without GCE the code works fine.

    (Btw: The GCE example code works fine on my machine.)
  • I've checked your example again and found something. You excluded the GCE from execution. When I do that too then no error occurs anymore. I know too little about Gideros so I don't know what this feature exactly is for and why GCE crashes when I don't activate the exclusion checkbox ... yet ...
  • zvardinzvardin Member
    Accepted Answer
    It could be because if you don't set the GCE code as a dependency of your file that it doesn't run until afterwards. Gideros by default automatically includes all Lua files, but you need to manage which order they fire in.
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Oh yes, GCE is excluded so it can be required in init.lua to be executed before everything else.
    If you don't exclude it, then it is executed twice and creates some different and unpredictable magic :D
  • NiicodemusNiicodemus Member
    Accepted Answer
    @seppsepp, I recently did some work on matrix stuff, and it ended up allowing me to write a completely drop-in implementation of adding anchor support to all sprites. It might work for you if you haven't gotten anything else to work since you posted this question. I just remembered this and figured I'd throw this out there.

    https://github.com/nshafer/AnchorSprite

    Thanks,
    Nathan Shafer
    +1 -1 (+2 / -0 )Share on Facebook
  • bowerandybowerandy Guru
    edited June 2013
    @Niicodemus, I'm finding your AnchorSprite stuff very useful. Great Job!

    However, I find that nearly every time I want to use setAnchorPoint() I actually want the object to stay in the same position. This is probably because I'm loading scenes from SVG and the initial positions are set relative to top left. However, I imagine this could be useful in many other cases too.

    I've written a method, resetAnchorPoint() that does this for simple cases i.e. if the Sprite is not rotated. I wonder if you'd consider adding a more general case to your AnchorSprite module. This is my version:
    function Sprite:resetAnchorPoint(ax, ay)
    	-- Change the anchor point but maintain the same onscreen position.
    	-- Implemented in Sprite rather than Bitmap in order to be compatible with Nathan Shafer's AnchorSprite.
    	--
    	local parent=self:getParent()
    	local x, y=self:getBounds(parent)
    	self:setAnchorPoint(ax, ay)
    	local x1, y1=self:getBounds(parent)
    	self:setPosition(self:getX()+x-x1, self:getY()+y-y1)
    end
    best regards
    +1 -1 (+1 / -0 )Share on Facebook
  • @bowerandy, I don't use my own AnchorSprite at all in my SVG parser, as SVG transforms are always relative to 0,0. At least for the parts I've done. Is there some other part of the spec that isn't relative to top left?

    Nathan Shafer
  • @Niicodemus, I use SVG to load in Gideros scenes. Once they are loaded, I grab hold of the objects (Bitmaps, Shapes, TextFields) and then convert some of them into classes that are part my application and apply animations to others.

    Often, especially when applying animations, I need the anchor point to be at the centre of the object - which is where AnchorSprite comes in. Currently, using setAnchorPoint() will cause the objects to move from their SVG positions, which is obviously not what I want - hence my use of resetAnchorPoint() above.

    I thought this might be quite a common activity but, if it's not, don't worry about it and I'll just add resetAnchorPoint() to my BhHelpers library.

    best regards
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.