Composer Display Images inside a Function

Yep. I forward referenced all my variables so I can use them in any of the phases so I think my variable scope is fine. For some reason it won’t work. But I might test your method and see if I can accomplish the same thing in a different format and maybe that will work. Thanks Alex for the help. If you say it should work then maybe there’s something I’m not catching in the code.

One small suggestion is to make all of your asset names lowercase. Not that this should impact this problem, but you’ll probably run into fewer issues in the future if you make all names lowercase.

OK. Thanks. I think I was running into some problems because of that. Thanks for the tip. I will be using that. So you’re saying my “inventoryHUD.png” should be “inventoryhud.png” and the UseStuff function should just be usestuff. Right?

actual Lua syntax doesn’t present a problem with cases, but it’s usually best to use lowercase for assets. 

Ok I will keep that in mind when I write the rest of the code. Alex, thanks for your time. You’ve been a great help.

Composer and Storyboard are very alike in how you deal with display objects. If you do not put a created display object in the scene’s view group, it will sit on top of the scene and not be managed by Composer (or Storyboard).  If you put the object in the group, then it will be managed by the scene manager.

The scene object’s view group (nothing more than a display.newGroup() for all practical purposes) is referenced as:

scene.view

This means that any display object can simply be done via:

scene.view:insert( object )

anywhere in the scene.  Both Composer and Storyboard support some advanced features where thinking about scenes as objects is helpful, so when the events fire that call scene:create(), scene:show() etc., the scene object is passed to those event functions as “self” The “:” operator between the object and the function name causes “self” to be the first parameter, which is the object itself and hidden from the parameter list.  This is why in those functions we do:

local sceneGroup = self.view

because self.view is scene.view.  If you want the object to be managed, put it in the scene’s group, else it will just sit on top.

Rob

Thanks Rob for the response. The function that I posted above was before I took it into composer so when I transferred it over I did add the display objects to the scene group. Thanks again for the information Rob it’s very useful to know and I always appreciate your comments.