码迷,mamicode.com
首页 > Web开发 > 详细

JS游戏控制时间代码

时间:2019-03-16 14:10:08      阅读:235      评论:0      收藏:0      [点我收藏+]

标签:inf   游戏   加载   htm   box   append   call   setattr   +=   

 

var canvas = new HGAME.canvas();
var testBox=document.getElementById(‘boxRender‘);
testBox.appendChild(canvas.dom);
var animate=new HGAME.animate({
action:function(){
canvas.render();
}
});
var colorObj={
r:0,
g:0,
b:0
};
function initColor(){
var div=null;
var initColor=document.getElementById("colorSelect");
for(var r=0;r<255;r+=65){
for(var b=0;b<255;b+=65){
for(var g=0;g<255;g+=65){
div=document.createElement("div");
div.setAttribute("class","item");
div.setAttribute("data-r",r);
div.setAttribute("data-g",g);
div.setAttribute("data-b",b);
div.style.backgroundColor="rgba("+r+","+g+","+b+","+"1)";
initColor.appendChild(div);
div.onclick=function(){
document.getElementById("nowSelectColor").style.backgroundColor="rgba("+this.getAttribute("data-r")+","+this.getAttribute("data-g")+","+this.getAttribute("data-b")+","+"1)";
colorObj.r=this.getAttribute("data-r");
colorObj.g=this.getAttribute("data-g");
colorObj.b=this.getAttribute("data-b");
}
}
}
}
}
initColor();
/*创建img数据*/
function changeImgColor(img,r,g,b){
var c=document.createElement("canvas");
var txt= c.getContext("2d");
c.width=img.width;
c.height=img.height;
txt.drawImage(img,0,0);
var data=txt.getImageData(0,0, c.width, c.height);
for(var q=0;q<data.data.length;q+=4){
if(data.data[q+3]>100){
data.data[q]=r;
data.data[q+1]=g;
data.data[q+2]=b;
}
}
txt.putImageData(data,0,0);
return c;
}
var div=document.createElement("div");

function changeDraw(num){
/*加载数据*/
var source=new HGAME.source({
loadCall:function(num,allNum){
div.innerHTML="加载资源"+num+"/"+allNum;
div.setAttribute("class","tool");
testBox.appendChild(div);
},
loaded:function(){
testBox.removeChild(div);
var img=new HGAME.Object2D({
img:this.data[0],
w:500,
h:500,
x:0,
y:0
});
canvas.child=new Array();
canvas.add(img);

var THIS = this;
img.child=new Array();
each(this.data,function(intX){
if(intX>=1){
img.add(new HGAME.Object2D({
x:whxyInfo[num][intX-1].x,
y:whxyInfo[num][intX-1].y,
w:whxyInfo[num][intX-1].w,
h:whxyInfo[num][intX-1].h,
img:THIS.data[intX],
isClick:true,
clickFun:function(){
if(typeof this.bufferImg=="undefined"){
this.bufferImg=this.img;
this.img=changeImgColor(this.bufferImg,colorObj.r,colorObj.g,colorObj.b);
}else{
this.img=changeImgColor(this.bufferImg,colorObj.r,colorObj.g,colorObj.b);
}
}
}));
}
});
animate.stop();
animate.run();
},
data:data[num]
});

}
changeDraw(0);
//

JS游戏控制时间代码

标签:inf   游戏   加载   htm   box   append   call   setattr   +=   

原文地址:https://www.cnblogs.com/blogst/p/10542100.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!