Skip to content

Commit

Permalink
Changed Mirage.Renderer.drawImage arguments format
Browse files Browse the repository at this point in the history
  • Loading branch information
chrome committed May 13, 2012
1 parent 80634d1 commit b5b8420
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 5 deletions.
12 changes: 11 additions & 1 deletion src/components/renderer.coffee
Expand Up @@ -19,7 +19,16 @@ class Mirage.Renderer
getContext: ->
@context

drawImage: (x, y, angle, scale, image, imageX, imageY, imageW, imageH) ->
drawImage: (image, options = {}) ->
x = options.x || 0
y = options.y || 0
scale = options.scale || 1
angle = options.angle || 0
imageX = options.cropStartX || 0
imageY = options.cropStartY || 0
imageW = options.cropWidth || image.width - imageX
imageH = options.cropHeight || image.height - imageY

image = image.get() if image.get?
@context.translate(x, y)
@context.rotate(-angle)
Expand All @@ -33,5 +42,6 @@ class Mirage.Renderer
@context.scale(1 / scale, 1 / scale)
@context.rotate(angle)
@context.translate(-x, -y)
@

clear: ->
31 changes: 27 additions & 4 deletions test/app.coffee
Expand Up @@ -3,7 +3,30 @@ window.onload = ->
rm.add new Mirage.ImageResource('ship', '/images/spaceship.png')

rm.loadAll ->
Mirage.getRenderer().drawImage(500, 50, 0, 1, rm.get('ship'))
Mirage.getRenderer().drawImage(100, 100, Math.PI / 3, 2, rm.get('ship'))
Mirage.getRenderer().drawImage(200, 300, Math.PI / 5, 1.5, rm.get('ship'))
Mirage.getRenderer().drawImage(300, 300, 0, 1, rm.get('ship'))
Mirage.getRenderer()
.drawImage(
rm.get('ship')
x: 200
y: 200
cropStartX: 42
cropWidth: 42
cropHeight: 42
angle: Math.PI / 3
)
.drawImage(
rm.get('ship')
x: 200
y: 100
cropWidth: 42
cropHeight: 42
angle: Math.PI / 5
scale: 2
)
.drawImage(
rm.get('ship')
x: 100
y: 100
cropStartX: 42
cropWidth: 42
cropHeight: 42
)

0 comments on commit b5b8420

Please sign in to comment.