2013-04-04 69 views
0

當我將舞臺光標設置爲無。我無法以某種方式訪問​​我的形狀(Startscreen.startButton)eventlistener。當我不隱藏我的光標時,我可以點擊它。當從舞臺上移除光標時,Eventlistener不在收聽

我做錯了什麼?

function initStartscreen() { 
    startscreenLayer = new createjs.Container(); 

    createMenuCursor(); 

    stage.addEventListener("stagemousemove", mouseMove); 
    stage.enableMouseOver(2); 
    stage.cursor = 'none'; 

    Startscreen = new Startscreen(); 

    startscreenLayer.addChild(Startscreen.background); 

    startscreenLayer.addChild(Startscreen.startButton); 
    startscreenLayer.addChild(Startscreen.startText); 

     startscreenLayer.addChild(Startscreen.highscoreButton); 
     startscreenLayer.addChild(Startscreen.highscoreText); 

     stage.addChildAt(startscreenLayer); 

    stage.update(); 

    Startscreen.startButton.addEventListener('click', function() { 
     alert(1); 
    }); 
} 

function Startscreen() { 
    this.background = new createjs.Shape(); 
    this.background.graphics 
     .beginFill('pink') 
     .drawRect(0, 0, stage.canvas.width, stage.canvas.height); 

    this.startButton = new createjs.Shape(); 
    this.startButton.graphics 
     .beginFill('#000') 
     .drawRect(0, 0, 250, 50) 
    this.startButton.x = (stage.canvas.width/2)-125; 
    this.startButton.y = 150; 
    this.startButton.name = "startButton"; 

    this.startText = new createjs.Text('Start', '30px Calibri', '#FFF'); 
    this.startText.x = this.startButton.x + 95; 
    this.startText.y = this.startButton.y + 7; 
} 

即時更新: 即使我剝離一切都關掉,只留下我的onload這是行不通的initStartscreen()

它必須是一些分層問題,或者因爲我在我的高分層創建了一個後退按鈕,當我從主菜單中使用它時,它會起作用。但是在玩過我的遊戲並轉到相同頁面/功能後,後退按鈕不起作用。

有沒有辦法讓我添加到頂層的圖層呢?

回答

0

我必須承認有點困惑,我可能需要澄清你的問題!

我知道你隱藏了光標,然後期望用戶找到一個帶有「不可見」光標的開始按鈕嗎? - 你對用戶意味着什麼? :p

如果您覺得stage.cursor='none'行爲異常,您可以使用CSS在最新版本的IE,FF和Chrome中將光標設置爲「無」。在「隱形」狀態下,鼠標事件是仍然是發射。下面的代碼和一個小提琴:http://jsfiddle.net/m1erickson/qBw9P/

$("#theStageCanvas").click(function(){ $("#theStageCanvas").css("cursor","none"); }); 

或者你有多個階段,要做出一個底部階段響應點擊事件,即使是在它頂部的階段?

您可以關閉事件監聽這樣的頂層上:

topStage.onClick=null; 
topStage.onMouseDown=null; 
topSstage.onMouseUp=null; 
topStage.onMouseMove=null; 
+0

哈哈,很明顯,我已經得到了以下mouseX和mouseY的;-)點擊是在畫布上的東西的位圖。所以,jQuery並不是我所害怕的適合解決方案。 – CaptainCarl 2013-04-11 10:31:05