Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
[solved] Sprites don't parent — Gideros Forum

[solved] Sprites don't parent

jack0088jack0088 Member
edited April 2012 in General questions
Somehow I just don't get it...
I have three Sprites: Group, sprite1, sprite2
Group is en empty Sprite. The two others are Lines. Then I parent them:
Group:addChild( sprite1 )
Group:addChild( sprite2 )
stage:addChild( Group )
Look at the output of stage! The parenting doesn't work! Every sprite points to itself as parent and child. Should't sprite1 and sprite2 point to Group as a __parent?
stage = {
|  __userdata = "userdata: 0x10610fd28"
|  __children = {
|  |  userdata: 0x104e8c330 = {
|  |  |  id = "Group"
|  |  |  __parent = {} -- stage (self reference)
|  |  |  __userdata = "userdata: 0x10611d1c8"
|  |  |  __children = {
|  |  |  |  userdata: 0x104e89310 = {
|  |  |  |  |  id = "sprite1"
|  |  |  |  |  __parent = {} -- stage.__children.userdata: 0x104e8c330 (self reference)
|  |  |  |  |  __children = {
|  |  |  |  |  |  userdata: 0x104e804e0 = {
|  |  |  |  |  |  |  __userdata = "userdata: 0x10611d238"
|  |  |  |  |  |  |  __parent = {} -- stage.__children.userdata: 0x104e8c330.__children.userdata: 0x104e89310 (self reference)
|  |  |  |  |  |  }
|  |  |  |  |  }
|  |  |  |  |  __userdata = "userdata: 0x10611f8b8"
|  |  |  |  }
|  |  |  |  userdata: 0x104e80770 = {
|  |  |  |  |  id = "sprite2"
|  |  |  |  |  __parent = {} -- stage.__children.userdata: 0x104e8c330 (self reference)
|  |  |  |  |  __children = {
|  |  |  |  |  |  userdata: 0x104e7bb90 = {
|  |  |  |  |  |  |  __userdata = "userdata: 0x10611b008"
|  |  |  |  |  |  |  __parent = {} -- stage.__children.userdata: 0x104e8c330.__children.userdata: 0x104e80770 (self reference)
|  |  |  |  |  |  }
|  |  |  |  |  }
|  |  |  |  |  __userdata = "userdata: 0x106124178"
|  |  |  |  }
|  |  |  }
|  |  }
|  }
}
Owltwins. Smart design and creative code.
»Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!

Comments

  • For me, parenting works. With that little piece of code it is hard to tell what is wrong with your code.
  • jack0088jack0088 Member
    edited April 2012
    can you try mine, please?
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • MikeHartMikeHart Guru
    edited April 2012
    I don't know what you do with all this printing, but if parenting would not work, you would not see the two lines on the canvas. So I guess it is your algorythm to analyse this data structure.
  • I am not sure if sprites are simple Lua tables like you expect them to be.
  • If I use "inspect.lua" to print "stage", I get a structure like the following (I've added comments) which has the parenting like you'd expect:
    <1>{
      __children = <2>{
        [<userdata 1>] = <img class="emoji" src="http://forum.gideros.rocks/resources/emoji/heart.png" title="<3" alt="<3" height="20" />>{
          __children = <4>{
            [<userdata 2>] = <5>{
              __parent = <table 3>,
              __userdata = <userdata 5>,
              id = "sprite1", -- "sprite2" parent is table 3 (i.e., "Group")
     
              __parent = <table 3>,
              __userdata = <userdata 9>,
              id = "sprite2",  -- "sprite2" parent is table 3 (i.e., "Group")
            }
          },
          __parent = <table 1>,
          __userdata = <userdata 10>,
          id = "Group",   --  "Group" parent is table 1 (which is the top level table, i.e., the stage)
        }
      },
    }
    I think your print_r routine is misleading you a bit. If I use "setPosition" on Group, both sprite1 and sprite2 move. If I use "setPosition" on sprite1, just sprite1 moves. This is the behavior I'd expect if the parenting was working correctly.

    --ND
  • really? ohh.. didn't thought my print_r would produce wrong results.
    How did you use the inspect.lua to get this clean output? When I was using it, it gave me the metatables and other things also, so the output was confusing and unreadable due to a lot of data.
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
  • It also gives me confusing and difficult to read output :). In the example above, I manually removed the extra junk.

    Also, I don't think you're print routine is giving you wrong results...just difficult to interpret results.
  • I'll keep on trying to locate my problems.. Thank you all again, very appreciate this community and the help!
    Owltwins. Smart design and creative code.
    »Gideros Illustrator« - [svg|xml] scene designer using Adobe Illustrator®™ Within one line of code!
Sign In or Register to comment.