limeJS Demo学习
2014-04-24 14:33
525 查看
goog.provide('test.events4'); goog.require('lime'); goog.require('lime.CoverNode'); goog.require('lime.Director'); goog.require('lime.Layer'); goog.require('lime.Scene'); goog.require('lime.Sprite'); goog.require('lime.animation.MoveTo'); goog.require('lime.animation.RotateBy'); goog.require('lime.animation.ScaleTo'); goog.require('lime.animation.Spawn'); test.WIDTH = 600; test.HEIGHT = 400; test.start = function() { //director test.director = new lime.Director(document.body, test.WIDTH, test.HEIGHT); test.director.makeMobileWebAppCapable(); //为游戏在IOS端运行提供支持 var gamescene = new lime.Scene; //创建游戏视图 var layer = (new lime.Layer).setPosition(100, 100); //创建图层 gamescene.appendChild(layer); //将图层加到游戏视图上 var box = (new lime.Sprite).setSize(100, 100).setFill(0, 0, 100); //创建矩形 layer.appendChild(box); //将矩形加到画布上 goog.events.listen(box, ['mousedown', 'touchstart'], function(e) { //监听对象为box 监听事件为mousedown或者touchstart function为回调函数 this.setFill(0, 100, 0); //this指box,改变被点击物体的颜色 e.startDrag(false, new goog.math.Box(0, 10, 200, -10)); // FALSE 指dragging not relates to center position, math.box创建拖拽区域,四个参数分别为上界,左界,下界,右界 var t = this; e.swallow(['mouseup', 'touchend'], function() {t.setFill(0, 0, 100)}); //处理紧随其后的鼠标放开事件,function为事件回调函数 }); box = (new lime.Sprite).setSize(50, 50).setFill(100, 0, 0).setPosition(200, 50); //创建第二个盒子 layer.appendChild(box); goog.events.listen(box, ['mousedown', 'touchstart'], function(e) { e.startDrag(true, new goog.math.Box(0, 250, 100, 150)); }); box = (new lime.Sprite).setSize(30, 30).setFill(0, 100, 100).setPosition(100, 150); //创建第三个盒子 layer.appendChild(box); goog.events.listen(box, ['mousedown', 'touchstart'], function(e) { e.startDrag(false, new goog.math.Box(150, 250, 150, 0)); }); // set active scene test.director.replaceScene(gamescene); //将视图替换为我们创建的视图。 }; goog.exportSymbol('test.start', test.start); //导出后的文件名,外部文件可以通过该名字访问该函数
相关文章推荐
- javascript 中 dom.getAttribute(“value”) 与dom.value的差异
- javascript高级程序设计笔记(二)
- ExtJS4 给同一个formpanel不同的url
- JavaScript学习08 Cookie对象
- 不错的JS
- js 冒泡事件的处理
- js星星评价
- javascript之数组操作
- json中对特殊字符的处理
- ExtJS4 自动生成控制grid的列显示、隐藏的checkbox
- JavaScript学习07 内置对象
- js脚本类库(lib)之字符串处理
- JavaScript中七种函数调用方式及对应 this 的含义
- 利用JScript/CSS 编程技术模拟实现TABView控件
- JavaScript 事件模型 事件处理机制
- 隐藏的表单写在JS里提高响应效率
- javaScript 语言精髓
- js 数组 var arr=[] 的用法总结
- json byte array fingerprint example
- js 面向对象 继承