Hello Hendrix,
Sure, here is a way:
--imageUtils.lua local imageUtils = {} function imageUtils.createCenteredIR(name, xPos, yPos) local img = display.newImageRect( name..".png", 0, 0 ) img.x = xPos img.y = yPos img:setReferencePoint( display.CenterReferencePoint ) return img end return imageUtils --main.lua local imageUtils = require "imageUtils" local happyDog = imageUtils.createCenteredIR("happyDog", xPos, yPos) local happyDog2 = imageUtils.createCenteredIR("happyDog2", xPos, yPos) local unhappyDog = imageUtils.createCenteredIR("unhappyDog", xPos, yPos)
Is there a easy way to do this with i.e. a rightClick and a util class?
Here is the way we recommend (btw the shortcut for autocomplete is ctrl-space)
Step 1: require your image Utils library (you only need to do this once per file):
http://view.xscreenshot.com/b3e0f61936ad6a36a1644eb0d4bee262
Step 2: invoke autocomplete after imageUtils.
http://view.xscreenshot.com/f0cf8b291085268c2feb6626f74bbf75
Step 3: invoke autocomplete inside quotes:
http://view.xscreenshot.com/8f9a0053a996406b13f55df5e9c5c592
You will have much less code duplication and produce much more shorter, readable, maintainable, and testable code this way.
Regards,
M.Y. Developers