您的位置:首页 > Web前端 > JavaScript

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);                //导出后的文件名,外部文件可以通过该名字访问该函数
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: