我想在我的畫布上隨意拖動圖像的圖像,但這樣做我有一個問題,即一旦該圖像是在負座標,我得到一個條件,其拖動畫布上閃爍
mouseX - negativeImageCoords // 200 - minus 210 = 410
讓我的形象像畫布上的爆米花小貓一樣跳躍,而不是想要的效果。
這裏是我的代碼,我希望這是愚蠢的東西,我可以把這個到是累了..
function (e) {
var
// The mouse x and y positions
mx = e.offsetX,
my = e.offsetY,
// The last known position
lx = cache.lx, // These are from a JSON object
ly = cache.ly;
// The temporary image
var img = $('#loadedImage');
// Get the image context
var canvas_context = this.mask();
cache.lx = (mx - lx);
cache.ly = (my - ly);
console.log(mx, lx);
console.log(my, ly);
// Redraw
canvas_context.drawImage(img.get(0), cache.lx, cache.ly, img.width(), img.height());
}
這裏的屏蔽功能(包括在情況下,行爲人..
function() {
var mask_name = 'circle';
var context = ctx.context();
var mask;
var isSameMask = false;
var composition = 'lighter';
// Add a check to see if it's the same mask
if (cache.mask && cache.mask.src) {
if (cache.mask.src !== 'images/masks/' + mask_name + '.png') {
isSameMask = false;
}
}
// If we don't have a cached mask, load it and cache it
if (!cache.mask && !isSameMask) {
// Create a new mask
mask = new Image;
// Draw when its loaded
mask.onload = function() {
//ctx.clear();
context.drawImage(this, 0, 0);
context.globalCompositeOperation = composition;
};
mask.src = 'images/masks/' + mask_name + '.png';
// Set the cache as this new mask
cache.mask = mask;
imageEvents.size(0);
} else {
ctx.clear();
// It's cached, so just redraw it
context.drawImage(cache.mask, 0, 0);
context.globalCompositeOperation = composition;
}
return context;
}
爲什麼圖像跳來跳去?
它必須指出的是,我已經拋出了一起針對appjs項目,從大家的幫助/意見是極大的讚賞。
恭喜。不要忘記標記自己是正確的;-) – guypursey
感謝哥們:)我會做一次它讓我在6小時內 –