js对象碰撞检测.docx
文本预览下载声明
!doctypehtmlhtmlheadmetaname=Authorcontent=flashlizi - metaname=Keywordscontent=HTML5,canvas,casual frameworkmetaname=Descriptioncontent=HTML5 canvas experimentmetahttp-equiv=content-typecontent=text/html; charset=utf-8/titleObject Collision - CasualJS Framework/titlelinktype=text/csshref=css/style.cssmedia=screenrel=stylesheet/scripttype=text/javascriptsrc=/webHorse/resouces/js/casual-0.1.min.js/scriptscripttype=text/javascriptvar canvas, context, stage;var logo, img_pig, img_bird1, img_bird2, img_bird2;var pig, bird1, bird2, bird3;function init(){//init canvascanvas = document.getElementById(canvas);context = canvas.getContext(2d);//imageslogo = document.getElementById(logo);img_pig = document.getElementById(pig);img_bird1 = document.getElementById(bird1);img_bird2 = document.getElementById(bird2);img_bird3 = document.getElementById(bird3);start();}function start(){//create stagestage = new Stage(context);stage.setFrameRate(10);bird1 = new Bitmap(img_bird1);bird1.x = 80;bird1.y = 50;stage.addChild(bird1);var bound = bird1.getRect(stage);var rect = new Shape();rect.alpha = 0.3;rect.graphics.lineStyle(1, #fff).drawRect(bound.x+0.5, bound.y+0.5, bound.width, bound.height);stage.addChild(rect);bird2 = new Bitmap(img_bird2);bird2.x = 300;bird2.y = 80;stage.addChild(bird2);bound = bird2.getRect(stage);rect = new Shape();rect.alpha = 0.3;rect.graphics.lineStyle(1, #fff).drawRect(bound.x+0.5, bound.y+0.5, bound.width, bound.height);stage.addChild(rect);bird3 = new Bitmap(img_bird3);bird3.x = 500;bird3.y = 70;stage.addChild(bird3);bound = bird3.getRect(stage);rect = new Shape();rect.alpha = 0.3;rect.graphics.lineStyle(1, #fff).drawRect(bound.x+0.5, bound.y+0.5, bound.width, bound.height);stage.addChild(rect);//mouse event labellabel = new Text();label.x = 160;label.y = 400;label.color = #fff;label.font = 18px Arial;label.align = start;label.text = Please try to drag the pig over the birds on top;stage.addChild(label);var label2 = casual.clone(label);label2.x = 95;label2.y
显示全部