第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Canvas 內(nèi)部元素如何實現(xiàn) mouseover/mousemove 事件?

Canvas 內(nèi)部元素如何實現(xiàn) mouseover/mousemove 事件?

一只萌萌小番薯 2019-04-16 20:27:39
我在使用Collie引擎來開發(fā)一個簡單的游戲,它提供了mousedown、mouseup、click這三個鼠標(biāo)事件,但是我想實現(xiàn)的功能是:當(dāng)我的鼠標(biāo)移到元素上的時候,顯示該元素的名字。但這個引擎并沒有提供mouseover或mousemove事件。Canvas是不是只能通過獲取指針在畫面上的坐標(biāo),然后判斷是否在元素的范圍,來模擬這個事件?如果是的話,有什么好的算法,用來判斷指針是否在x、y、width、height(或者是圓型x、y、radius)范圍中?如果不是的話,應(yīng)該怎么做呢?
查看完整描述

2 回答

?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗 獲得超10個贊

自己看源代碼不就好了
和我想得一樣,就是循環(huán)判斷,比大小確定範(fàn)圍,直到找到爲(wèi)止。
想要實現(xiàn)mouseover啥的,自己照著_fireEvent調(diào)用_getTargetOnHitEvent即可
/**
*????????????????????????????
*
*@param{Object}e?????
*@param{String}sType?????,mouse????????????
*@param{Number}nX???????????
*@param{Number}nY???????????
*@return{Boolean}????????????????
*@private
*/
_fireEvent:function(e,sType,nX,nY){
varoDisplayObject=null;
varbIsNotStoppedBubbling=true;
//???????????????????????????????????????
if(sType!=="mousemove"&&!collie.Renderer.isStopEvent(sType)){
varaDisplayObjects=this._oLayer.getChildren();
oDisplayObject=this._getTargetOnHitEvent(aDisplayObjects,nX,nY);
//mousedown??????????
if(oDisplayObject){
bIsNotStoppedBubbling=this._bubbleEvent(oDisplayObject,sType,e,nX,nY);
if(sType==="mousedown"){
this._setMousedownObject(oDisplayObject);
}
if(sType==="mouseup"){
this._unsetMousedownObject(oDisplayObject);
}
}
}
//mouseup???????????
if(sType==="mouseup"&&this._getMousedownObject()!==null){
oDisplayObject=this._getMousedownObject();
this._bubbleEvent(oDisplayObject,sType,e,nX,nY);
this._unsetMousedownObject(oDisplayObject);
}
/**
*click???,????????touchstart,touchend???????????????????click????????d
*@namecollie.Layer#click
*@event
*@param{Object}htEvent
*@param{collie.DisplayObject}htEvent.displayObject????
*@param{HTMLEvent}htEvent.event?????
*@param{Number}htEvent.x??x??
*@param{Number}htEvent.y??y??
*/
/**
*mousedown???,????????touchstart????????.
*@namecollie.Layer#mousedown
*@event
*@param{Object}htEvent
*@param{collie.DisplayObject}htEvent.displayObject????
*@param{HTMLEvent}htEvent.event?????
*@param{Number}htEvent.x??x??
*@param{Number}htEvent.y??y??
*/
/**
*mouseup???,????????touchend????????.
*@namecollie.Layer#mouseup
*@event
*@param{Object}htEvent
*@param{collie.DisplayObject}htEvent.displayObject????
*@param{HTMLEvent}htEvent.event?????
*@param{Number}htEvent.x??x??
*@param{Number}htEvent.y??y??
*/
/**
*mousemove???,????????touchmove????????.
*@namecollie.Layer#mouseup
*@event
*@param{Object}htEvent
*@param{collie.DisplayObject}htEvent.displayObject????
*@param{HTMLEvent}htEvent.event?????
*@param{Number}htEvent.x??x??
*@param{Number}htEvent.y??y??
*/
if(bIsNotStoppedBubbling){//stop??Layer???????????
this._oLayer.fireEvent(sType,{
event:e,
displayObject:oDisplayObject,
x:nX,
y:nY
});
}
return!!oDisplayObject;
},
/**
*?????????
*-????????????????
*@private
*@param{Array|collie.DisplayObject}vDisplayObject
*@param{Number}nX?????x??
*@param{Number}nY?????y??
*@return{collie.DisplayObject|Boolean}
*/
_getTargetOnHitEvent:function(vDisplayObject,nX,nY){
varoTargetObject=null;
if(vDisplayObjectinstanceofArray){
for(vari=vDisplayObject.length-1;i>=0;i--){
//????
if(vDisplayObject[i].hasChild()){
oTargetObject=this._getTargetOnHitEvent(vDisplayObject[i].getChildren(),nX,nY);
//??????
if(oTargetObject){
returnoTargetObject;
}
}
//???
oTargetObject=this._getTargetOnHitEvent(vDisplayObject[i],nX,nY);
//??????
if(oTargetObject){
returnoTargetObject;
}
}
}else{
returnthis._isPointInDisplayObjectBoundary(vDisplayObject,nX,nY)?vDisplayObject:false;
}
},
/**
*DisplayObject????PointX,PointY????????
*
*@private
*@param{collie.DisplayObject}oDisplayObject
*@param{Number}nPointX??????X??
*@param{Number}nPointY??????Y??
*@return{Boolean}?????true
*/
_isPointInDisplayObjectBoundary:function(oDisplayObject,nPointX,nPointY){
//?????????????????????
if(
!oDisplayObject._htOption.useEvent||
!oDisplayObject._htOption.visible||
!oDisplayObject._htOption.width||
!oDisplayObject._htOption.height||
(oDisplayObject._htOption.useEvent==="auto"&&!oDisplayObject.hasAttachedHandler())
){
returnfalse;
}
varhtHitArea=oDisplayObject.getHitAreaBoundary();
//??????????
if(
htHitArea.left<=nPointX&&nPointX<=htHitArea.right&&
htHitArea.top<=nPointY&&nPointY<=htHitArea.bottom
){
//hitArea??????????????
if(!oDisplayObject._htOption.hitArea){
returntrue;
}else{
varhtPos=oDisplayObject.getRelatedPosition();
//??Point????????
nPointX-=htPos.x;
nPointY-=htPos.y;
//transform??
varaHitArea=oDisplayObject._htOption.hitArea;
aHitArea=collie.Transform.points(oDisplayObject,aHitArea);
returnthis._isPointInPolygon(aHitArea,nPointX,nPointY);
}
}
returnfalse;
},
                            
查看完整回答
反對 回復(fù) 2019-04-16
  • 2 回答
  • 0 關(guān)注
  • 1242 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號