38 lines
889 B
CoffeeScript
38 lines
889 B
CoffeeScript
Crafty.defineScene "Battle", ->
|
|
|
|
# free viewport
|
|
Crafty.viewport.clampToEntities = false
|
|
|
|
# attach viewport to an (invisible) entity twice as big as a playmat
|
|
Crafty.viewport.follow (
|
|
Crafty.e('2D, Canvas')
|
|
.attr {
|
|
w: 1 * CONF.playmat.w
|
|
h: 2 * CONF.playmat.h
|
|
}
|
|
.origin('center')
|
|
)
|
|
|
|
# scale viewport automatically (show that new entity)
|
|
Crafty.bind 'ViewportResize', ->
|
|
sX = @viewport._width / (1 * CONF.playmat.w)
|
|
sY = @viewport._height / (2 * CONF.playmat.h)
|
|
|
|
@viewport.scale Math.min(sX, sY)
|
|
return
|
|
|
|
# force scale adjustment
|
|
Crafty.trigger 'ViewportResize'
|
|
|
|
# Example playmats at https://imgur.com/a/VSosu#cwGQdAS
|
|
Crafty.sprite 997, 582, '//i.imgur.com/cwGQdAS.png',
|
|
playmat: [
|
|
0
|
|
0
|
|
]
|
|
|
|
# Place example playmats
|
|
Crafty.e 'playmat, AllyPlaymat'
|
|
Crafty.e 'playmat, EnemyPlaymat'
|
|
|
|
return
|