日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

javascript canvas檢測小球碰撞

瀏覽:30日期:2023-06-21 17:43:50

本文實例為大家分享了javascript canvas實現檢測小球碰撞的具體代碼,供大家參考,具體內容如下

定義一個canvas標簽

<div class='cnavasInfo'> <canvas ></canvas></div>

函數以及相關的邏輯處理

export default { data() { return { canvas: null, ctx: null, arcObj: {} }; }, mounted() { this.canvas = document.getElementById('canvas'); this.ctx = this.canvas.getContext('2d'); // this.move(); // 矩形的邊緣碰撞函數 // this.moveArc(); // 繪制碰撞圓形,對象形式 this.moveRect() }, methods: { move() { let x = 0; let y = 0; let width = 100; let height = 100; let speedX = 2; let speedY = 2; let ctx = this.ctx; ctx.fillStyle = 'red'; ctx.fillRect(x, y, width, height); setInterval(() => { ctx.clearRect(x, y, this.canvas.width, this.canvas.height); x += speedX; if (x > this.canvas.width - width) { speedX *= -1; } else if (x < 0) { speedX *= -1; } y += speedY; if (y > this.canvas.height - height) { speedY *= -1; } else if (y < 0) { speedY *= -1; } ctx.fillRect(x, y, width, height); }, 10); // this.requestmove(x,y,width,height,ctx,speedX,speedY); // 請求幀的動畫過程 }, requestmove(x, y, width, height, ctx, speedX, speedY) { ctx.clearRect(x, y, this.canvas.width, this.canvas.height); x += speedX; if (x > this.canvas.width - width) { speedX *= -1; } else if (x < 0) { speedX *= -1; } y += speedY; if (y > this.canvas.height - height) { speedY *= -1; } else if (y < 0) { speedY *= -1; } ctx.fillRect(x, y, width, height); window.requestAnimationFrame( this.requestmove(x, y, width, height, ctx, speedX, speedY) ); }, moveArc(x, y, r, speedX, speedY) { this.x = x; this.y = y; this.r = r; this.speedX = speedX; this.speedY = speedY; this.moveUpdata = function() { this.x += this.speedX; if (this.x > this.canvas.width - this.r) { this.speedX *= -1; } else if (this.x < 0) { this.speedX *= -1; } this.y += this.speedY; if (this.y > this.canvas.height - this.r) { this.speedY *= -1; } else if (this.y < 0) { this.speedY *= -1; } }; }, moveRect(){ // 面向對象編程 function Rect(x,y,width,height,color,speedX,speedY,ctx,canvas) { this.x = x; this.y = y; this.width = width; this.height = height; this.color = color this.speedX = speedX this.speedY = speedY this.ctxRect = ctx this.canvas = canvas } Rect.prototype.draw = function() { this.ctxRect.beginPath(); this.ctxRect.fillStyle = this.color this.ctxRect.fillRect(this.x,this.y,this.width,this.height) this.ctxRect.closePath(); } Rect.prototype.move = function() { this.x += this.speedX if(this.x > this.canvas.width - this.width){ this.speedX *= -1 } else if(this.x < 0){ this.speedX *= -1 } this.y += this.speedY if(this.y > this.canvas.height - this.height){ this.speedY *= -1 } else if(this.y < 0){ this.speedY *= -1 } } let rect1 = new Rect(0,100,100,100,’red’,2,2,this.ctx,this.canvas) let rect2 = new Rect(300,100,100,100,’blue’,-2,-2,this.ctx,this.canvas) // rect1.draw(); // rect2.draw() let animate = ()=>{ this.ctx.clearRect(0,0,this.canvas.width,this.canvas.height) rect1.draw() rect1.move() rect2.draw() rect2.move() let rect1Min = rect1.x; let rect1Max = rect1.x + rect1.width let rect2Min = rect2.x let rect2Max = rect2.x + rect2.width let min = Math.max(rect1Min,rect2Min) let max = Math.min(rect1Max,rect2Max) if(min < max){ rect1.speedX *= -1; rect1.speedY *= 1; rect2.speedX *= -1 rect2.speedY *= 1 } window.requestAnimationFrame(animate) } animate() } }};

樣式控制

#canvas { border: 1px solid black;}

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持好吧啦網。

標簽: JavaScript
相關文章:
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
日韩av一区二| 日韩欧美综合| 夜久久久久久| 免费成人网www| 亚洲小说欧美另类婷婷| 国产精品久久久久久久免费观看| 国产精品中文字幕亚洲欧美| 欧美一区激情| 国产伦理久久久久久妇女| 国产亚洲一区| 国产日韩一区二区三区在线| 亚洲精一区二区三区| 免费视频最近日韩| 日韩影院免费视频| 日韩激情一区二区| 国产麻豆一区| 精品九九久久| 午夜精品久久久久久久久久蜜桃| 97se综合| 色88888久久久久久影院| 日韩精品水蜜桃| 亚洲午夜在线| 亚洲日本欧美| 国产黄色一区| 欧美日韩精品免费观看视完整| 欧美手机在线| 亚洲永久字幕| 亚洲欧美日本国产 | 国产欧美日韩免费观看| 国产欧美日韩视频在线| 精品色999| 久久五月天小说| 石原莉奈在线亚洲二区| 日本欧美大码aⅴ在线播放| 国产精品超碰| 国产99久久| 自拍自偷一区二区三区| 国产欧美在线| 成人啊v在线| 中文字幕一区二区三区在线视频| 视频在线观看91| 国产精品久久久久毛片大屁完整版| 精品国产乱码| 红桃视频欧美| 国产亚洲一区二区三区不卡| 色黄视频在线观看| 亚洲欧美日韩国产一区二区| 国产三级精品三级在线观看国产| 中文字幕色婷婷在线视频| 亚洲欧美日本日韩| 久久av中文| 自拍日韩欧美| 国产精品一区二区免费福利视频| 欧美少妇精品| 中文字幕中文字幕精品| 麻豆国产精品一区二区三区| 成人自拍av| 欧美一区网站| 国产在线日韩| 国产日韩中文在线中文字幕 | 国产精品chinese| 99久久九九| 日韩高清国产一区在线| 四虎成人av| 亚洲一区二区三区中文字幕在线观看| 精品久久不卡| 老司机精品视频在线播放| 国产欧美一区二区三区精品酒店| 日韩午夜在线| 国产剧情一区| 亚洲国内欧美| 国产精品美女久久久久久不卡| 国精品一区二区三区| 国产精品777777在线播放 | 久久精品二区亚洲w码| 91超碰国产精品| 欧美激情日韩| 日韩中文字幕不卡| 99国产精品一区二区| 日本精品国产| 国产一区二区精品| 久久久久久久欧美精品| 啪啪国产精品| 日韩黄色在线观看| 久久精品动漫| 国产精品22p| 日韩精品一级中文字幕精品视频免费观看 | 亚洲色图网站| 日韩精品永久网址| 91综合久久爱com| 亚洲精品123区| 色一区二区三区| 国产乱子精品一区二区在线观看| 一区二区视频欧美| 天堂√中文最新版在线| 国产精品极品在线观看| 一区在线观看| 群体交乱之放荡娇妻一区二区| 国产精品2023| 午夜久久av| 在线亚洲国产精品网站| 香蕉成人av| 正在播放日韩精品| 麻豆成人av在线| 国产一卡不卡| 欧美日韩网址| 日韩精品91亚洲二区在线观看| 羞羞答答国产精品www一本| 色婷婷久久久| 色88888久久久久久影院| 精品亚洲自拍| 日本99精品| 蜜桃视频免费观看一区| 在线 亚洲欧美在线综合一区| 亚洲91久久| 亚洲成av在线| 久久蜜桃资源一区二区老牛| 欧美男人天堂| 成人高清一区| 精品福利久久久| 国产一区二区三区探花| 久久免费影院| 国产一区调教| 国产不卡一区| 久久毛片亚洲| 亚洲电影有码| 91亚洲国产| 国产一区三区在线播放| 成人污污视频| 久久男人av资源站| 日韩精品2区| 免费观看久久av| 亚洲综合三区| 日本中文字幕一区二区| 国产丝袜一区| 精品国产中文字幕第一页| 高清日韩欧美| 亚洲午夜视频| 中文字幕日韩高清在线 | 天堂成人国产精品一区| 免费在线观看日韩欧美| 日韩有吗在线观看| 欧美亚洲三级| 久久亚洲道色| 99久久精品费精品国产| 另类国产ts人妖高潮视频| 亚洲精品四区| 69堂免费精品视频在线播放| 国产精品亚洲综合色区韩国| 麻豆精品久久| 电影天堂国产精品| 美日韩精品视频| 国产日韩免费| 国产成人精品三级高清久久91| 日韩高清欧美| 精品亚洲美女网站| 国产精品亚洲二区| 国产成人77亚洲精品www| 999久久久精品国产| 日产午夜精品一线二线三线| 成人在线免费观看91| 不卡中文字幕| 免费欧美在线视频| 国产精品白丝久久av网站| 亚洲精品美女91| 青青青国产精品| 91亚洲国产高清| 欧美成人高清| 欧美一区成人| 精品中文字幕一区二区三区四区| 国产99在线| 色88888久久久久久影院| 在线一区二区三区视频| 91精品国产自产观看在线| 精品国产a一区二区三区v免费| 国产66精品| 国产亚洲网站| 国产精品嫩模av在线| 精品伊人久久| 黄色亚洲精品| 日韩超碰人人爽人人做人人添| 精品国产成人| 九九在线精品| 国产精品欧美三级在线观看| 亚洲三级欧美| 国产精品91一区二区三区| 欧美在线精品一区| 精品国产乱码久久久| 天堂av在线一区| 国产一卡不卡| 不卡在线一区二区| 欧美日韩尤物久久| 久久国产精品亚洲77777| 精品精品99| 黑丝一区二区三区| 国产成年精品| 三级欧美在线一区| 成人在线免费观看网站| 欧美在线资源| 国产一区二区三区亚洲综合|