Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]

Inserting to a specific group index
Started by Guest Feb 03 2010 11:31 AM

- - - - -
2 replies to this topic
This topic has been archived. This means that you cannot reply to this topic.
[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Guests

From the API guide: group:insert( [index,] child, [, resetTransform] )

I want to insert an item at the back of the group, or group[1]. If i have a group and I add an item, say it has 4 items in it, the 5th item will be group[5]. I could probably do a for loop to re order things for me but it seems like I should be able to insert something into a group at any index I want, but it doesn't seem to work, and the for loop could end up being costly cpu wise. Probably not for what I'm doing, but if it were a bigger project.

Ideally, I would want it to work like this (assume I've already got 4 items in my group):

local img = display.newImage("foo.png",0,0)
group:insert(img[1]) -- where I insert "img" into whatever index I want, bumping everything else up

Even the manual says:
Inserts child at index into group, shifting up other elements as necessary

Unless I'm reading it wrong...

Am I right in thinking that the group method was added to Lua by Ansca?
uid: 0 topic_id: 443 reply_id: 300443

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Observer

  • 21 posts
  • Guests

group:insert(1, img) -- inserts displayObject at the bottom of the stack
group:insert(img) -- insert displayObject at the top of the stack
uid: 3544 topic_id: 443 reply_id: 856

[TOPIC: post.html]


[GLOBAL: userInfoPane.html]
  • Guests

I swear I tried that...

uid: 0 topic_id: 443 reply_id: 858