forked from bukidev/RenJS
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackgroundManager.js
More file actions
47 lines (40 loc) · 1.5 KB
/
Copy pathBackgroundManager.js
File metadata and controls
47 lines (40 loc) · 1.5 KB
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
40
41
42
43
44
45
46
function BackgroundManager(){
this.backgrounds = {};
this.current = null;
this.add = function(name,animated,framerate){
this.backgrounds[name] = RenJS.storyManager.backgroundSprites.create(game.world.centerX,game.world.centerY,name);
this.backgrounds[name].name = name;
this.backgrounds[name].anchor.set(0.5);
this.backgrounds[name].alpha = 0;
if (animated){
this.backgrounds[name].animated = true;
this.backgrounds[name].animations.add("run",null,framerate);
}
}
this.set = function (name) {
if (this.current){
this.current.alpha = 0;
}
this.current = this.backgrounds[name];
this.current.alpha = 1;
if (this.current.animated){
this.current.animations.play("run",null,true);
}
}
this.show = function(name,transition){
var oldBg = this.current;
this.current = name ? this.backgrounds[name] : null;
// console.log("showing bg "+name);
// debugger;
if (this.current.animated){
this.current.animations.play("run",null,true);
}
return transition(oldBg,this.current,{x:game.world.centerX,y:game.world.centerY},1,RenJS.storyManager.backgroundSprites);
}
this.hide = function(bg,transition){
return this.show(null,transition ? transition : RenJS.transitions.FADEOUT);
}
this.isBackground = function(actor){
return _.has(this.backgrounds,actor);
}
}