Lufylegend庫學習筆記1 繪圖操作及滑鼠事件,lufylegend學習筆記

來源:互聯網
上載者:User

Lufylegend庫學習筆記1 繪圖操作及滑鼠事件,lufylegend學習筆記

這幾天對於網頁前端有點興趣,學習了一下Canvas的相關知識。

看到Lufylegend庫之後,感覺很棒,有一種在寫AS的感覺。今天入門第一站,寫了一個畫板。

是一個非常簡易的畫板,但是可以看到一些重要的思想。

代碼如下:

<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><title>Mouse Event</title><script src="http://static.blog.csdn.net/scripts/jquery.js" type="text/javascript"></script><script src="http://lufylegend.com/js/lufylegend-1.9.7.min.js"></script></head><body><div id="tester"></div><script>init(1, "tester", 500, 350, main);var stage;function main() {LGlobal.setDebug(false);trace("on debug");stage = new LSprite();addChild(stage);/*stage.graphics.add(function(coordX, coordY) {LGlobal.canvas.fillStyle="#333";LGlobal.canvas.beginPath();LGlobal.canvas.fillRect(0, 0, 500, 350);});*/stage.graphics.drawRect(0,"#000", [0, 0, 500, 350], true, "#333");stage.graphics.lineStyle(5, "#F00");stage.addEventListener(LMouseEvent.MOUSE_DOWN, onMouseDown);stage.addEventListener(LMouseEvent.MOUSE_UP, onMouseUp);}function onMouseDown(event) {trace("mouse down");stage.graphics.beginPath();stage.graphics.moveTo(event.offsetX, event.offsetY);stage.addEventListener(LMouseEvent.MOUSE_MOVE, onMouseMove);}function onMouseUp(event) {stage.removeEventListener(LMouseEvent.MOUSE_MOVE, onMouseMove);trace("mouse up");}function onMouseMove(event) {stage.graphics.lineTo(event.offsetX, event.offsetY);stage.graphics.stroke();stage.graphics.moveTo(event.offsetX, event.offsetY);trace("mouse move");}</script></body></html>

真的與Flash很像。trace函數用於測試,如果將LGlobal.setDebug設定為true的話,可以直接得到輸出。具體可以參考:官方文檔trace介紹

以下是網頁啟動並執行:


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.