我是新的AppMobi世界的新手,所以你能帮帮我吗?
我创造了一个图像对象,并把它画到了舞台上。我的问题是,我想要向对象添加一个事件。
我使用以下方法设置了图像:
function objImage(imageURL,x,y,width,height) {
this.imgCanvas = new Image();
this.imageURL = imageURL;
this.loaded = false;
this.x = x;
this.y = y;
this.height = height;
this.width = width;
this.draw = function() {
if (this.width == null || this.height == null)
{
ctx.drawImage(this.imgCanvas,this.x,this.y);
}
else
{
ctx.drawImage(this.imgCanvas,this.x,this.y,this.width,this.height);
}
}
}我把它画到舞台上:
var usercontrols_left = new objImage('images/left.png',10,HEIGHT-100,50,50);
usercontrols_left.draw();现在我想向'usercontrols_left‘添加一个事件,例如检测用户触摸/单击它的时间。
发布于 2012-10-01 20:17:57
我不知道你是否在使用directCanvas。我认为这一解决办法应该是两全其美的。
捕获touchstart事件,并根据它的坐标判断它是否位于左侧元素的位置。如果是,则执行需要触发的命令。
伪码:
Canvas.addEventListener('touchstart', startTouch, false);
function startTouch(){
if(touch.x<60&&touch.x>10&&touch.y<height-50&&touch.y>height-100)
{ handleLeftControl(); }
}编辑*使用webview的示例:在you视图中使用:
<div id="Leftbutn" ontouchstart="AppMobi.canvas.execute('switchCommand(\'leftBTNdown\');')" ontouchend="AppMobi.canvas.execute('switchCommand(\'leftBTup\');')" ></div>然后,在directCanvas方面,您只需根据希望在开关或函数中执行的操作来处理这些命令。
https://stackoverflow.com/questions/12639902
复制相似问题