at the moment I have to target an image using interfaceGroup[9], I would rather use interfaceGroup[“imageName”] can I do this
Cheers [import]uid: 5354 topic_id: 633 reply_id: 300633[/import]
at the moment I have to target an image using interfaceGroup[9], I would rather use interfaceGroup[“imageName”] can I do this
Cheers [import]uid: 5354 topic_id: 633 reply_id: 300633[/import]
Hello Matthew,
Yes, tables can be indexed with numbers or with strings. See also:
http://www.lua.org/pil/2.5.html
There is even a shorthand:
interfaceGrop[“imageName”]
is the same as:
interfaceGroup.imageName
Cheers, Arjan
[import]uid: 4824 topic_id: 633 reply_id: 1253[/import]
Thanks for the reply, I still cant get it to work though
–main code
local image_buttons = display.newImage(“buttons.png”,0,246)
interfaceGroup:insert(image_buttons)
–in a function
local interfaceGroup = interfaceGroup
transition.to(interfaceGroup.image_buttons, { alpha=0, time=300 } );
–or to write it the other way
transition.to(interfaceGroup[“image_buttons”], { alpha=0, time=300 } );
neither work, could it be a bug with the transition.to? [import]uid: 5354 topic_id: 633 reply_id: 1254[/import]
Hello Matthew,
I believe you are mixing two concepts.
interfaceGroup:insert(image\_buttons)
is a call to a Corona function that inserts an object into a group that was created with:
display.newGroup()
When you write interfaceGroup.image_buttons you are indexing the table interfaceGroup and retrieving the field image_buttons (which will not be there).
Is interfaceGroup a real group created with display.newGroup() ? If so, you can simply apply the transition to the whole group:
transition.to(interfaceGroup, { alpha = 0, time = 300 })
On the other hand, if you just thought of interfaceGroup as a place to store things (a table), you would have to write
interfaceGroup.image\_buttons = image\_buttons (instead of the insert)
And then your transition code would work.
Greetings, Arjan
[import]uid: 4824 topic_id: 633 reply_id: 1259[/import]
Thank for the help Arjan
Im grouping a bunch of objects together for animation purposed and I am using display.newGroup() to create the group. I insert all the interface elements into the group and then animate away and 99% of the time its cool.
What I am trying to do (from within a function), where local interfaceGroup = interfaceGroup, is to target only certain images in interfaceGroup.
Imagine im rotation interfaceGroup based on user interaction and when the function fires it goes into interface group and selects only certain images within that group that it wants to transition alpha to 0. Im using multiple groups as I need some complex animations / layout and I was thinking the easiest way was to reference the group (which is global in the main.lua) from within a function (that was required from a separate .lua file) as the group is the only thing I can access from within the function (as it sees the global).
im using this at the moment transition.to(interfaceGroup[9], { alpha = 0, time = 300 }) where 9 is the place in the group where the image im looking for exists. I was hoping to not have to reference the key directly as I keep reordering the group as I build the application. Its not a deal breaker but im trying to learn best practice and quickly as I code, design etc… and every time I learn something I rewrite the code.
This is also a learning experience for me in terms of lua programming… so forgive my noob questions. (in flash I would be using _parent or _root or what ever to target the image directly) [import]uid: 5354 topic_id: 633 reply_id: 1261[/import]
If you want to target a specific image you can also refer to it by its name. So, inside the function you could write:
transition.to(image\_buttons, { ... })
You do not have to go through the group.
[import]uid: 4824 topic_id: 633 reply_id: 1262[/import]
ok I will try that tonight, I didnt think that would work as only the group is global and the function targeting the group can only see the group. Thats because the group is global (no local declaration in main.lua) and the function is required from a separate lua file and cant see any local declarations in the main.lua. Hence why I made the group a global and I am referencing everything by going into the group.
im probably making things harder for myself but I couldnt figure out a way to get required .lua files to see variables / groups declared locally in the main.lua file [import]uid: 5354 topic_id: 633 reply_id: 1263[/import]
You’re right, the image has to be global if you want to refer to it from another file.
[import]uid: 4824 topic_id: 633 reply_id: 1270[/import]