Jump to content

[TOPIC: topicViewTemplate]
[GLOBAL: userSmallPhoto]
Photo

How to replace display objects within groups
Started by Michael Flad Oct 28 2018 03:17 AM

4 replies to this topic

Best Answer roaminggamer , 28 October 2018 - 07:26 AM

Things you can do do:

 

 

I think perhaps you forgot this, but you can insert at a specific index:

group:insert( [index,] child, [, resetTransform] )

[TOPIC CONTROLS]
[/TOPIC CONTROLS]
[modOptionsDropdown]
[/modOptionsDropdown]
[reputationFilter]
[TOPIC: post.html]
#1

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 181 posts
  • Corona SDK

Is there any efficient way to replace a display object within a group object that's already built. I.e. I, obviously, want to keep the order of all the current childs the way they are.
 
And no, I don't want to "rebuild" the whole group by reinserting everyt single child each time and I also don't want to create an additional useless parent group object for every single display object I use.


[TOPIC: post.html]
#2

nick_sherman

[GLOBAL: userInfoPane.html]
nick_sherman
  • Corona Geek

  • 1,610 posts
  • Corona SDK

Not that I know of. Can't you just swap the image on the existing display object and re-size if necessary?

 

https://docs.coronalabs.com/tutorial/media/swapImages/index.html#fill-swap



[TOPIC: post.html]
#3

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 181 posts
  • Corona SDK

It's more a general question and less about a single actual issue. It's a problem I, more or less, stumble over in almost every project I work on as, in the end, it's primarily about missing functionality to modify the children of a group.
 
One actual situation is that I work on a game that's kind of a long list of "blocks" containing mostly text but also buttons, images, small subhierarchies (which then are actually using a parent group of course) and the contents may change based on the players actions.
 
Another one is, that I'm working on a text rendering plugin and I'd like to offer a kind of wrapper object users of the plugin can use instead of Coronas text objects. But depending on the usage (f.i. if the users changes the text contents) I have to destroy the display object I internally use and create a new one and I'd love to have this just added to the very same childindex of the same parent object of the previously destroyed one.
 
Of course I can handle this manually by just reorganizing all children of my parent group but it's simply not how it should be done. It's like solving a problem that needs random access with a linked list.


[TOPIC: post.html]
#4

roaminggamer

[GLOBAL: userInfoPane.html]
roaminggamer
  • Corona Geek

  • 7,286 posts
  • Corona SDK

  Best Answer

Things you can do do:

 

 

I think perhaps you forgot this, but you can insert at a specific index:

group:insert( [index,] child, [, resetTransform] )

  • Michael Flad and sporkfin like this

[TOPIC: post.html]
#5

Michael Flad

[GLOBAL: userInfoPane.html]
Michael Flad
  • Contributor

  • 181 posts
  • Corona SDK

Ah thanks Ed for the remeinder, yeah, I haven't thought about the optional parameters for insert as I'm so used to build and manage my sorted lists upfront before just inserting all the objects in the right order.

 

Partially because it's still a less than ideal solution because I assume internally the childs are stored within an array (otherwise primarily accessing by index would not make sense) so each time a display objects is removed and reinserted Corona probably has to move all the references starting from index+1 to the end of the array.

 

For the project that caused me to open this thread though this is a good enough solution. But in general it's still an area where Corona could do better - in another project I have to resort a list of a few hundred sprites each frame but that's something for another topic :)




[topic_controls]
[/topic_controls]