-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdream.html
94 lines (86 loc) · 2.52 KB
/
dream.html
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<!DOCTYPE html>
<html>
<head>
<title>moviecliptest</title>
<script type="text/javascript" src="lib/seajs/sea.js"></script>
<script type="text/javascript">
seajs.config({
base:'file:///E:/github/Dream/dream/',
alias:{
},
charset:'utf-8',
timeout:20000,
debug:1
});
seajs.use('core/Dream',function(Dream){
var game=window.game={};
var display=Dream.display;
var events=Dream.events;
var DisplayObject=display.DisplayObject;
var MovieClip=display.MovieClip;
var EventDispatcher=events.EventDispatcher;
var box=new MovieClip();
box.x=100;
box.y=100;
box.width=100;
box.height=100;
box.render=function(ctx){
ctx.save();
ctx.transform(2,0,0,2,100,100);
ctx.fillStyle="rgba(255,0,0,128)";
ctx.fillRect(this.x,this.y,this.width,this.height);
ctx.restore();
};
box.update=function(){
this.x+=1;
this.y+=1;
};
var can=document.getElementById('can');
var ctx=can.getContext('2d');
function onEnterFrame(){
try{
ctx.clearRect(0,0,1000,600);
ctx.drawImage(game.asset.bg,0,0);
ctx.drawImage(game.asset.topbar,100,0);
ctx.drawImage(game.asset.zom,600,400);
clearInterval(game.timer);
}catch(e){
clearInterval(game.timer);
console.log(e);
}
}
//ȫ���¼�������
var stageEvent=game.stageEvent=new EventDispatcher();
stageEvent.addEventListener('loadComplete',onLoadComplete);
function onLoadComplete(){
game.timer=window.setInterval(onEnterFrame,25);
}
game.asset={};
var loadComplete=false;
var images=window.images=[{name:'bg',src:'images/zom/bg/background.jpg'},
{name:'topbar',src:'images/zom/bg/top.gif'},
{name:'zom',src:'images/zom/Zombie/Zombie2.gif'}];
var totalCount=images.length;
var countLoaded=0;
for(var i=0,len=totalCount;i<len;i++){
var imgInfo=images[i],
img=new Image();
img.onload=function(){
countLoaded++;
if(countLoaded==totalCount){
loadComplete=true;
game.stageEvent.dispatchEvent({type:'loadComplete',target:this});
}
}
game.asset[imgInfo.name]=img;
img.src=imgInfo.src;
}
});
</script>
</head>
<body>
<div id="ctn" style="text-align:left;">
<canvas width="1000" height="600" id="can" style="border:none;"></canvas>
</div>
</body>
</html>