Advertisement
lvs

newImage wrapper

lvs
Mar 4th, 2013
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.62 KB | None | 0 0
  1. local _M = {}
  2.  
  3. -- Set reference point
  4. function _M.setRP (object, ref_point)
  5.     ref_point = string.lower(ref_point)
  6.     if ref_point == 'topleft' then
  7.         object:setReferencePoint(display.TopLeftReferencePoint)
  8.     elseif ref_point == 'topright' then
  9.         object:setReferencePoint(display.TopRightReferencePoint)
  10.     elseif ref_point == 'topcenter' then
  11.         object:setReferencePoint(display.TopCenterReferencePoint)
  12.     elseif ref_point == 'bottomleft' then
  13.         object:setReferencePoint(display.BottomLeftReferencePoint)
  14.     elseif ref_point == 'bottomright' then
  15.         object:setReferencePoint(display.BottomRightReferencePoint)
  16.     elseif ref_point == 'bottomcenter' then
  17.         object:setReferencePoint(display.BottomCenterReferencePoint)
  18.     elseif ref_point == 'centerleft' then
  19.         object:setReferencePoint(display.CenterLeftReferencePoint)
  20.     elseif ref_point == 'centerright' then
  21.         object:setReferencePoint(display.CenterRightReferencePoint)
  22.     elseif ref_point == 'center' then
  23.         object:setReferencePoint(display.CenterReferencePoint)
  24.     end
  25. end
  26.  
  27. function _M.newImage (filename, params)
  28.     params = params or {} -- allow to pass filename only
  29.     local w, h = params.w or 480, params.h or 320 --some values you use more often
  30.     -- Load an image
  31.     local image = display.newImageRect(filename, w, h)
  32.     -- Set reference point
  33.     if params.rp then
  34.         _M.setRP(image, params.rp)
  35.     end
  36.     if params.g then
  37.         g:insert(image)
  38.     end
  39.     -- Place it to desired position
  40.     image.x = params.x or 0
  41.     image.y = params.y or 0
  42.     return image
  43. end
  44.  
  45. return _M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement