<script type="text/javascript" src="js/jquery.min.js"></script> <script type="text/javascript" src="js/easeljs.min.js"></script>
<canvas id="mycanvas" width="800" height="500"></canvas> <script > // 圖片預(yù)加載 function loadImages(sourse,callback){ var count = 0, images = {}, imgNum = 0; for(src in sourse){ imgNum++ } for(src in sourse){ images[src] = new Image(); images[src].onload = function(){ if(++count >= imgNum){ callback(images); } } images[src].src = sourse[src]; } } $(document).ready(function(){ var stage = new createjs.Stage("mycanvas") createjs.Ticker.addEventListener("tick", stageBreakHandler); // 圖片預(yù)加載 var sources = { groundImg : "img/ground.png", hill1 : "img/hill1.png" , hill2 : "img/hill2.png" , ren : "img/ren.png" , }; var sp,ground,hill1,hill2 loadImages(sources, function(images){ // 天空背景 var sky = new createjs.Shape() sky.graphics.beginLinearGradientFill(["#7dcef6","#c1e2f2"],[0, 1], 0, 580, 0, 500).drawRect(0,0,800,500) // 山 hill1 = new createjs.Bitmap(images.hill1) hill1.set({x:-300,y:150,alpha:0.5,scaleX:3,scaleY:5}); hill1.iw = images.hill1.width hill2 = new createjs.Bitmap(images.hill2) hill2.set({x:210,y:500-220,scaleX:3,scaleY:3}); hill2.iw = images.hill2.width // 地板 ground = new createjs.Shape() ground.graphics.beginBitmapFill(images.groundImg).drawRect(0,0,800+images.groundImg.width,images.groundImg.height) ground.y = 500 - images.groundImg.height; ground.tileW = images.groundImg.width; // 人 var ss = new createjs.SpriteSheet({ "images": [images.ren], "frames": {"width":165,"height":292,count:64}, "animations" : { "run": [0,36,"jump",1.5], "jump":[36,63,"run"] } }) sp = new createjs.Sprite(ss,"run") sp.x = 100 sp.y = 500 - 292 - 79 stage.addChild(sky,hill1,hill2,ground, sp) stage.update(); }); function stageBreakHandler(event){ // event.delta -- 上一次tick到當(dāng)前tick的ms var deltaS = event.delta / 1000; ground.x = (ground.x - deltaS * 150) % ground.tileW; hill1.x = (hill1.x - deltaS * 30); hill2.x = (hill2.x - deltaS * 30); sp.x+=5 if(sp.x>=800){ sp.x = 0 hill1.x = -300; hill2.x = 200; } stage.update(); } }) </script>
1. 本站所有素材(未指定商用),僅限學(xué)習(xí)交流。
2. 會員在本站下載的原創(chuàng)商用和VIP素材后,只擁有使用權(quán),著作權(quán)歸原作者及17素材網(wǎng)所有。
3. 原創(chuàng)商用和VIP素材,未經(jīng)合法授權(quán),請勿用于商業(yè)用途,會員不得以任何形式發(fā)布、傳播、復(fù)制、轉(zhuǎn)售該素材,否則一律封號處理。
4. 本平臺織夢模板僅展示和個(gè)人非盈利用途,織夢系統(tǒng)商業(yè)用途請預(yù)先授權(quán)。