I am creating a game with composer scenes, using the scene template.
I am putting images into the sceneGroup (self.view) group when they are first created.
My question is what is the best way (best practice) to reference a specific image after it has been added to sceneGroup?
For example, if I create a player class with a player image that gets added to sceneGroup, and I wanted to manipulate the image through the class.
ex. size, position, sprite sequence.
Currently the solution I have come up with is to save the image’s position in the group to a variable right after it is added to the group, and reference it by its group number.
local player = {} local player\_mt = { \_\_index = player } player["new"] = function(group, name) local newPlayer = { name = name, image = display.newImageRect(group, "img/player.png", 32, 32), image = nil, gid = group.numChildren } return setmetatable( newPlayer, player\_mt ) end function player:test(group, px, py) group[self["gid"]].x = px group[self["gid"]].y = py print(self["name"]) print(group[self["gid"]].x) print(group[self["gid"]].y) end return player