我正在开发HTML5游戏.我需要在画布上绘制尾线并检查游戏中的交叉点,这是一个Tron风格的游戏.
我实际上是在使用JCanvas中的drawLine()函数,但是JCanvas没有为我提供检查行交集的方法,我挖掘了源代码并发现使用了ctx对象,并且在我使用的函数的最后,我返回了对象,所以我可以使用该ctx.isPointInPath()方法来实现我需要的,但不工作,false每次都返回...
我真的不明白路径是什么 - 只ctx.isPointInPath()返回true使用ctx.moveTo()after 设置的点ctx.beginPath()?或者它将返回true连续ctx.moveTo()使用2个连续s 之间的所有点ctx.lineTo()?
有什么用ctx.closePath()?
有什么区别:
{
ctx.closePath();
ctx.fill();
ctx.stroke();
}
Run Code Online (Sandbox Code Playgroud)
和:
{
ctx.fill();
ctx.stroke();
ctx.closePath();
}
Run Code Online (Sandbox Code Playgroud) 我使用 jCanvas 用 jQuery 制作传单编辑器:https ://projects.calebvans.me/jcanvas/
$(function () {
initCanvas();
$.datepicker.regional['fr'] = {
closeText: 'Fermer',
prevText: '<Préc',
nextText: 'Suiv>',
currentText: 'Aujourd\'hui',
monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Aout', 'Septembre', 'Octobre', 'Novembre', 'Décembre'],
monthNamesShort: ['Jan', 'Fev', 'Mar', 'Avr', 'Mai', 'Jun', 'Jul', 'Aou', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Dimanche', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi'],
dayNamesShort: ['Dim', 'Lun', 'Mar', 'Mer', 'Jeu', 'Ven', 'Sam'],
dayNamesMin: ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa'],
weekHeader: 'Sm',
dateFormat: 'dd-mm-yy',
firstDay: 1,
isRTL: false, …Run Code Online (Sandbox Code Playgroud)我正在使用jCanvas构建一个HTML5应用程序,我需要删除一个图层,这是画布上的黑色圆圈,你可以在这里看到代码.
var cvLingualWidth = 945;
var cvLingualHeight = 100;
var cvLingual = document.getElementById("cvLingual");
function drawGrid() {
var contextLingual = cvLingual.getContext("2d");
for (var y = 0.5; y < cvLingualHeight; y += 6) {
contextLingual.moveTo(0, y);
contextLingual.lineTo(cvLingualWidth, y);
}
contextLingual.strokeStyle = "#DDD";
contextLingual.stroke();
}
function drawCircle() {
$("#cvLingual").drawArc({
layer: true,
name: "circleLayer_18",
strokeStyle: "#000",
strokeWidth: 2,
x: 42,
y: 70,
radius: 8
});
}
function clearCircle() {
var circleLayer = $("#cvLingual").getLayer("circleLayer_18");
// TODO
}
$(function () {
drawGrid();
drawCircle();
$("#clear").click(function(){ …Run Code Online (Sandbox Code Playgroud)