Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local _M = {}
- -- Set reference point
- function _M.setRP (object, ref_point)
- ref_point = string.lower(ref_point)
- if ref_point == 'topleft' then
- object:setReferencePoint(display.TopLeftReferencePoint)
- elseif ref_point == 'topright' then
- object:setReferencePoint(display.TopRightReferencePoint)
- elseif ref_point == 'topcenter' then
- object:setReferencePoint(display.TopCenterReferencePoint)
- elseif ref_point == 'bottomleft' then
- object:setReferencePoint(display.BottomLeftReferencePoint)
- elseif ref_point == 'bottomright' then
- object:setReferencePoint(display.BottomRightReferencePoint)
- elseif ref_point == 'bottomcenter' then
- object:setReferencePoint(display.BottomCenterReferencePoint)
- elseif ref_point == 'centerleft' then
- object:setReferencePoint(display.CenterLeftReferencePoint)
- elseif ref_point == 'centerright' then
- object:setReferencePoint(display.CenterRightReferencePoint)
- elseif ref_point == 'center' then
- object:setReferencePoint(display.CenterReferencePoint)
- end
- end
- function _M.newImage (filename, params)
- params = params or {} -- allow to pass filename only
- local w, h = params.w or 480, params.h or 320 --some values you use more often
- -- Load an image
- local image = display.newImageRect(filename, w, h)
- -- Set reference point
- if params.rp then
- _M.setRP(image, params.rp)
- end
- if params.g then
- g:insert(image)
- end
- -- Place it to desired position
- image.x = params.x or 0
- image.y = params.y or 0
- return image
- end
- return _M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement