小程序
小游戏
企业微信
微信支付
扫描小程序码分享
做一个简单的画线功能,在模拟器上没有问题。在真机上看不到。
if (this.moveing)
{
ctx.beginPath();
ctx.lineWidth = '5'
ctx.strokeStyle = 'red'
ctx.moveTo(this.startX, this.startY);
ctx.lineTo(this.curX, this.curY);
ctx.stroke();
ctx.closePath();
}
3 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
环境无法复现,可否提供代码片段?
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
新建一个小游戏项目,使用飞机那个。然后再main.js的render函数中添加如下代码:
ctx.lineWidth =
'5'
ctx.setLineCap =
'square'
ctx.strokeStyle =
'white'
ctx.moveTo(0,0);
ctx.lineTo(400,400);
import
'./libs/weapp-adapter.js'
let ctx = canvas.getContext(
'2d'
)
export
default
class Main
constructor()
this
.bindLoop =
.loop.bind(
.aniId = window.requestAnimationFrame(
.bindLoop,
canvas
canvas.addEventListener(
'touchstart'
, ((e) =>
e.preventDefault()
.startX = e.touches[0].clientX
.startY = e.touches[0].clientY
}).bind(
))
'touchmove'
.curX = e.touches[0].clientX
.curY = e.touches[0].clientY
.moveing =
true
;
if
(
.touched)
.setAirPosAcrossFingerPosZ(x, y)
'touchend'
, ((e) => {
false
Render()
.moveing)
'red'
ctx.moveTo(
.startX,
.startY);
ctx.lineTo(
.curX,
.curY);
loop()
ctx.clearRect(0, 0, canvas.width, canvas.height);
.Render();
let app =
new
Main()
能做个代码片段吗
霄哥霄哥,帮我看看这个好不好啊
https://developers.weixin.qq.com/community/develop/doc/00000cd91884402911c723dfc51c00?highline=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%B9%B3%E5%8F%B0
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
环境无法复现,可否提供代码片段?
新建一个小游戏项目,使用飞机那个。然后再main.js的render函数中添加如下代码:
ctx.beginPath();ctx.lineWidth ='5'ctx.setLineCap ='square'ctx.strokeStyle ='white'ctx.moveTo(0,0);ctx.lineTo(400,400);ctx.stroke();ctx.closePath();import'./libs/weapp-adapter.js'let ctx = canvas.getContext('2d')exportdefaultclass Main{constructor(){this.bindLoop =this.loop.bind(this)this.aniId = window.requestAnimationFrame(this.bindLoop,canvas)canvas.addEventListener('touchstart', ((e) =>{e.preventDefault()this.startX = e.touches[0].clientXthis.startY = e.touches[0].clientY}).bind(this))canvas.addEventListener('touchmove', ((e) =>{e.preventDefault()this.curX = e.touches[0].clientXthis.curY = e.touches[0].clientYthis.moveing =true;if(this.touched)this.setAirPosAcrossFingerPosZ(x, y)}).bind(this))canvas.addEventListener('touchend', ((e) => {e.preventDefault()this.moveing =false;}).bind(this))}Render(){if(this.moveing){ctx.beginPath();ctx.lineWidth ='5'ctx.strokeStyle ='red'ctx.moveTo(this.startX,this.startY);ctx.lineTo(this.curX,this.curY);ctx.stroke();ctx.closePath();}}loop(){ctx.clearRect(0, 0, canvas.width, canvas.height);this.Render();this.aniId = window.requestAnimationFrame(this.bindLoop,canvas)}}let app =newMain()能做个代码片段吗
霄哥霄哥,帮我看看这个好不好啊
https://developers.weixin.qq.com/community/develop/doc/00000cd91884402911c723dfc51c00?highline=%E7%AC%AC%E4%B8%89%E6%96%B9%E5%B9%B3%E5%8F%B0