Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2016
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     Method DrawImageRect:Void(atlasItem:AtlasItem, x:float, y:float, width:float, height:float, sourceX:float, sourceY:float, sourceWidth:float, sourceHeight:float)
  2.         'need to take into account padding on atlas item (ugh)
  3.         Local newSourceX:= sourceX
  4.         Local newSourceY:= sourceY
  5.         Local newSourceWidth:= sourceWidth
  6.         Local newSourceHeight:= sourceHeight
  7.         Local newDestinationX:= x
  8.         Local newDestinationY:= y
  9.         Local newDestinationWidth:= width
  10.         Local newDestinationHeight:= height
  11.        
  12.         Local difference:Float
  13.        
  14.         Local scaleX:= width / sourceWidth
  15.         Local scaleY:= height / sourceHeight
  16.        
  17.         'left edge
  18.         If sourceX < atlasItem.paddingLeft
  19.             difference = (atlasItem.paddingLeft - sourceX)
  20.             newSourceX = 0.0
  21.             newDestinationX += difference * scaleX
  22.             newSourceWidth -= difference
  23.             newDestinationWidth -= difference * scaleY
  24.         Else
  25.             newSourceX -= atlasItem.paddingLeft
  26.         EndIf
  27.    
  28.         'top edge
  29.         If sourceY < atlasItem.paddingTop
  30.             difference = (atlasItem.paddingTop - sourceY)
  31.             newSourceY = 0.0
  32.             newDestinationY += difference * scaleY
  33.             newSourceHeight -= difference
  34.             newDestinationHeight -= difference * scaleY
  35.         Else
  36.             newSourceY -= atlasItem.paddingTop
  37.         EndIf
  38.        
  39.         'right edge
  40.         difference = (sourceX + sourceWidth) - (atlasItem.paddingLeft + atlasItem.width)
  41.         If difference > 0
  42.             newSourceWidth -= difference
  43.             newDestinationWidth -= difference * scaleX
  44.         EndIf
  45.        
  46.         'bottom edge
  47.         difference = (sourceY + sourceHeight) - (atlasItem.paddingRight + atlasItem.height)
  48.         If difference > 0
  49.             newSourceHeight -= difference
  50.             newDestinationHeight -= difference * scaleY
  51.         EndIf
  52.        
  53.         canvas.DrawRect(newDestinationX, newDestinationY, newDestinationWidth, newDestinationHeight, atlasItem.image, newSourceX, newSourceY, newSourceWidth, newSourceHeight)
  54.     End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement