日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
蘑菇與熊游戲開發(fā)第三回(讓熊動起來)

這一回我們讓熊動起來。

目前創(chuàng)新互聯(lián)已為上千家的企業(yè)提供了網(wǎng)站建設(shè)、域名、網(wǎng)頁空間、網(wǎng)站托管維護(hù)、企業(yè)網(wǎng)站設(shè)計、莫力達(dá)網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

預(yù)期達(dá)到效果:http://www.html5china.com/html5games/mogu/index2.html

一、先定義全局變量

 
 
 
  1. var bearEyesClosedImg = new Image();//閉著眼睛的熊熊       
  2. var horizontalSpeed = 2;//水平速度      
  3. var verticalSpeed = -2; //垂直速度,開始肯定是要向上飄,所以要負(fù)數(shù)      
  4. var bearAngle = 2;//熊旋轉(zhuǎn)的速度    

二、定義熊

首先定義一只公用熊

 
 
 
  1. //定義動物熊 Animal 繼承 游戲?qū)ο驡ameObject      
  2. function Animal() {};      
  3. Animal.prototype = new GameObject();//游戲?qū)ο驡ameObject      
  4. Animal.prototype.angle = 0;//旋轉(zhuǎn)的角度,(用來改變熊的旋轉(zhuǎn)速度)    

定義我們使用的熊

 
 
 
  1. //定義熊實例       
  2. var animal = new Animal();    

初始化熊

 
 
 
  1. bearEyesClosedImg.src = "images/bear_eyesclosed.png";//閉著眼睛的      
  2. animal.image = bearEyesClosedImg;//熊圖片      
  3. animal.x = parseInt(screenWidth/2);//x坐標(biāo)      
  4. animal.y = parseInt(screenHeight/2); //y坐標(biāo)    

三、描繪熊在畫布上

因為熊是相對移動的,所以我們要加一個基準(zhǔn)

 
 
 
  1. //以當(dāng)前熊的中心位置為基準(zhǔn)      
  2. ctx.translate(animal.x + (animal.image.width/2), animal.y + (animal.image.height/2));      
  3. //描繪熊      
  4. ctx.drawImage(animal.image, - (animal.image.width/2), - (animal.image.height/2));    

但是熊要旋轉(zhuǎn)啊,好的,想要改變它的角度,上面的代碼中加入旋轉(zhuǎn)

 
 
 
  1. //以當(dāng)前熊的中心位置為基準(zhǔn)      
  2. ctx.translate(animal.x + (animal.image.width/2), animal.y + (animal.image.height/2));      
  3. //根據(jù)當(dāng)前熊的角度輪換      
  4. ctx.rotate(animal.angle * Math.PI/180);      
  5. //描繪熊      
  6. ctx.drawImage(animal.image, - (animal.image.width/2), - (animal.image.height/2));    

上面的熊是不動的,為什么呢,因為x,y軸和角度沒變,因此我們再加上改變x,y和角度的代碼,于是上面的代碼變成了

 
 
 
  1. //改變移動動物X和Y位置      
  2. animal.x += horizontalSpeed;      
  3. animal.y += verticalSpeed;      
  4. //改變翻滾角度      
  5. animal.angle += bearAngle;      
  6. //以當(dāng)前熊的中心位置為基準(zhǔn)      
  7.         ctx.translate(animal.x + (animal.image.width/2), animal.y + (animal.image.height/2));      
  8. //根據(jù)當(dāng)前熊的角度輪換      
  9.     ctx.rotate(animal.angle * Math.PI/180);      
  10. //描繪熊      
  11.     ctx.drawImage(animal.image, - (animal.image.width/2), - (animal.image.height/2));    

到現(xiàn)目前為止熊已經(jīng)能滾動和移動了,最終代碼如下:

 
 
 
  1.         
  2.         
  3.         
  4.         
  5. 蘑菇動起來-html5中文網(wǎng)        
  6.      
  7.         
  8.         
  9.         
  10.         
  11.         
  12.             
  13.                
  14.         瀏覽器不支持html5,請下載支持html5的瀏覽器來觀看       
  15.                 
  16.     
        
  •                
  •        
  • 第三回就講到這了,第四回講熊碰撞邊界和蘑菇的事件

    原文鏈接:http://www.html5china.com/course/20110101_899.html


    網(wǎng)站題目:蘑菇與熊游戲開發(fā)第三回(讓熊動起來)
    網(wǎng)頁路徑:http://m.5511xx.com/article/ccdejcg.html