/
Midground.js
39 lines (30 loc) · 909 Bytes
/
Midground.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* @file 中景
* @author yumao [zhangyu38@baidu.com]
*/
define(function (require) {
var config = require('level/config');
var Midground = function (game, options) {
this.game = game;
this.image = null;
this.imagePrefix = options.imagePrefix;
this.index = options.index;
this._init();
};
Midground.prototype._init = function () {
var game = this.game;
var imageName = this.imagePrefix + '-' + this.index;
var image = game.add.tileSprite(
0, 0,
game.cache.getImage(imageName).width, game.height,
imageName
);
this.image = image;
image.tilePosition.x -= config.themes[this.index].offset;
// image.alpha = 0.8;
};
Midground.prototype.scroll = function (offset) {
this.image.tilePosition.x -= offset;
};
return Midground;
});