Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Method DrawImageRect:Void(atlasItem:AtlasItem, x:float, y:float, width:float, height:float, sourceX:float, sourceY:float, sourceWidth:float, sourceHeight:float)
- 'need to take into account padding on atlas item (ugh)
- Local newSourceX:= sourceX
- Local newSourceY:= sourceY
- Local newSourceWidth:= sourceWidth
- Local newSourceHeight:= sourceHeight
- Local newDestinationX:= x
- Local newDestinationY:= y
- Local newDestinationWidth:= width
- Local newDestinationHeight:= height
- Local difference:Float
- Local scaleX:= width / sourceWidth
- Local scaleY:= height / sourceHeight
- 'left edge
- If sourceX < atlasItem.paddingLeft
- difference = (atlasItem.paddingLeft - sourceX)
- newSourceX = 0.0
- newDestinationX += difference * scaleX
- newSourceWidth -= difference
- newDestinationWidth -= difference * scaleY
- Else
- newSourceX -= atlasItem.paddingLeft
- EndIf
- 'top edge
- If sourceY < atlasItem.paddingTop
- difference = (atlasItem.paddingTop - sourceY)
- newSourceY = 0.0
- newDestinationY += difference * scaleY
- newSourceHeight -= difference
- newDestinationHeight -= difference * scaleY
- Else
- newSourceY -= atlasItem.paddingTop
- EndIf
- 'right edge
- difference = (sourceX + sourceWidth) - (atlasItem.paddingLeft + atlasItem.width)
- If difference > 0
- newSourceWidth -= difference
- newDestinationWidth -= difference * scaleX
- EndIf
- 'bottom edge
- difference = (sourceY + sourceHeight) - (atlasItem.paddingRight + atlasItem.height)
- If difference > 0
- newSourceHeight -= difference
- newDestinationHeight -= difference * scaleY
- EndIf
- canvas.DrawRect(newDestinationX, newDestinationY, newDestinationWidth, newDestinationHeight, atlasItem.image, newSourceX, newSourceY, newSourceWidth, newSourceHeight)
- End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement