Hero always centered in camera in new hero levels when playing and not panning to drag.

This commit is contained in:
Nick Winter 2014-09-21 20:49:45 -07:00
parent 600e985259
commit 6cb8a2a019
4 changed files with 14 additions and 3 deletions

View file

@ -94,7 +94,7 @@ module.exports = class LevelLoader extends CocoClass
heroConfig ?= me.get('heroConfig')
heroConfig ?= {inventory: {}, thangType: '529ffbf1cf1818f2be000001'} # If we got here not from PlayLevelModal (like level editor preview), assign Tharin as the hero.
session.set 'heroConfig', heroConfig unless _.isEqual heroConfig, session.get('heroConfig')
url = "/db/thang.type/#{heroConfig.thangType}/version?project=name,components,original"
url = "/db/thang.type/#{heroConfig.thangType}/version"
@worldNecessities.push @maybeLoadURL(url, ThangType, 'thang')
for itemThangType in _.values(heroConfig.inventory)

View file

@ -204,6 +204,7 @@ module.exports = Surface = class Surface extends CocoClass
if @mouseInBounds isnt mib
Backbone.Mediator.publish('surface:mouse-' + (if mib then 'over' else 'out'), {})
@mouseInBounds = mib
@mouseIsDown = false
restoreWorldState: ->
frame = @world.getFrame(@getCurrentFrame())
@ -218,6 +219,8 @@ module.exports = Surface = class Surface extends CocoClass
updateState: (frameChanged) ->
# world state must have been restored in @restoreWorldState
if @playing and @heroSprite and not @mouseIsDown and @camera.newTarget isnt @heroSprite.imageObject and @camera.target isnt @heroSprite.imageObject
@camera.zoomTo @heroSprite.imageObject, @camera.zoom, 750
@camera.updateZoom()
@spriteBoss.update frameChanged
@dimmer?.setSprites @spriteBoss.sprites
@ -464,12 +467,14 @@ module.exports = Surface = class Surface extends CocoClass
event = onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e, worldPos: wop
Backbone.Mediator.publish 'surface:stage-mouse-down', event
Backbone.Mediator.publish 'tome:focus-editor', {}
@mouseIsDown = true
onMouseUp: (e) =>
return if @disabled
onBackground = not @stage.hitTest e.stageX, e.stageY
Backbone.Mediator.publish 'surface:stage-mouse-up', onBackground: onBackground, x: e.stageX, y: e.stageY, originalEvent: e
Backbone.Mediator.publish 'tome:focus-editor', {}
@mouseIsDown = false
onMouseWheel: (e) =>
# https://github.com/brandonaaron/jquery-mousewheel
@ -483,7 +488,6 @@ module.exports = Surface = class Surface extends CocoClass
Backbone.Mediator.publish 'surface:mouse-scrolled', event unless @disabled
#- Canvas callbacks
onResize: (e) =>
@ -515,6 +519,10 @@ module.exports = Surface = class Surface extends CocoClass
@camera.onResize newWidth, newHeight
#- Camera focus on hero
focusOnHero: ->
@heroSprite = @spriteBoss.spriteFor 'Hero Placeholder'
#- Real-time playback

View file

@ -1,5 +1,6 @@
CocoView = require 'views/kinds/CocoView'
template = require 'templates/play/level/level_loading'
utils = require 'lib/utils'
module.exports = class LevelLoadingView extends CocoView
id: 'level-loading-view'
@ -24,7 +25,8 @@ module.exports = class LevelLoadingView extends CocoView
@level = e.level
goalList = @$el.find('.level-loading-goals').removeClass('secret').find('ul')
for goalID, goal of @level.get('goals') when (not goal.team or goal.team is e.team) and not goal.hiddenGoal
goalList.append $('<li class="list-group-item header-font">' + goal.name + '</li>')
name = utils.i18n goal, 'name'
goalList.append $('<li class="list-group-item header-font">' + name + '</li>')
showReady: ->
return if @shownReady

View file

@ -360,6 +360,7 @@ module.exports = class PlayLevelView extends RootView
Backbone.Mediator.publish 'level:set-time', time: 0, frameOffset: state.frame
if @level.get('type', true) is 'hero'
Backbone.Mediator.publish 'tome:select-primary-sprite', {}
@surface.focusOnHero()
else if state.selected
# TODO: Should also restore selected spell here by saving spellName
Backbone.Mediator.publish 'level:select-sprite', thangID: state.selected, spellName: null