js笔记--1
1.创建一个layer层
var GameLayer = cc.Layer.extend({
_time:null,
_ship:null,
_backSky:null,
// 构造函数
ctor:function(){
this._super();
this.init();
}, //注意要有逗号 // 初始化函数
init:function () {
return true;
}, // 成员函数
scoreCounter:function () {
if (this._state == STATE_PLAYING) {
this._time++;
this._levelManager.loadLevelResource(this._time);
}
}, // 带参数
collide:function (a, b) {
var ax = a.x, ay = a.y, bx = b.x, by = b.y;
if (Math.abs(ax - bx) > MAX_CONTAINT_WIDTH || Math.abs(ay - by) > MAX_CONTAINT_HEIGHT)
return false; var aRect = a.collideRect(ax, ay);
var bRect = b.collideRect(bx, by);
return cc.rectIntersectsRect(aRect, bRect);
} // 最后一个可以不需要逗号 }); // 如果有需要通过切换场景的方式来进入下一个界面则可以创建这个方法、
// 在得到scene之后可以通过这个方式来进入
// cc.director.runScene(new cc.TransitionFade(1.2, scene));
GameLayer.scene = function () {
var scene = new cc.Scene();
var layer = new GameLayer();
scene.addChild(layer, 1);
return scene;
}; // 点击开始新游戏时会加载主游戏界面,这时候可能需要加载的资源会比较多
// 所以会用到预加载的方式、这也是成员函数,在点击按钮的时候响应
onNewGame:function (pSender) {
//load resources
cc.LoaderScene.preload(g_maingame, function () {
cc.audioEngine.stopMusic();
cc.audioEngine.stopAllEffects();
var scene = new cc.Scene();
scene.addChild(new GameLayer());
scene.addChild(new GameControlMenu());
cc.director.runScene(new cc.TransitionFade(1.2, scene));
}, this);
}, // 加载plist文件
cc.spriteFrameCache.addSpriteFrames(res.textureTransparentPack_plist); // 得到屏幕宽高
winSize = cc.director.getWinSize(); // 创建精灵,方式一
var sp = new cc.Sprite(res.loading_png);
sp.anchorX = 0;
sp.anchorY = 0;
sp.scale = MW.SCALE;
this.addChild(sp, 0, 1); //这里的this相当于lua中的self // 创建精灵方式二
var logo = new cc.Sprite(res.logo_png);
logo.attr({
anchorX: 0,
anchorY: 0,
x: 0,
y: MW.LOGOY,
scale: MW.SCALE
});
this.addChild(logo, 10, 1); // 创建按钮
var newGameNormal = new cc.Sprite(res.menu_png, cc.rect(0, 0, singalWidth, singalHeight));
var newGameSelected = new cc.Sprite(res.menu_png, cc.rect(0, singalHeight, singalWidth, singalHeight));
var newGameDisabled = new cc.Sprite(res.menu_png, cc.rect(0, singalHeight * 2, singalWidth, singalHeight)); var newGame = new cc.MenuItemSprite(newGameNormal, newGameSelected, newGameDisabled, function () {
// 按钮的响应函数
}.bind(this)); newGame.scale = MW.SCALE; // 设置属性
var menu = new cc.Menu(newGame, gameSettings, about);
menu.alignItemsVerticallyWithPadding(15);
this.addChild(menu, 1, 2); // 帧事件、
this.schedule(this.update, 0.1); update:function () {
if (this._ship.y > 750) {
this._ship.x = Math.random() * winSize.width;
this._ship.y = 10;
this._ship.runAction(cc.moveBy(
parseInt(5 * Math.random(), 10),
cc.p(Math.random() * winSize.width, this._ship.y + 750)
));
}
}, // 动作
this._ship = new cc.Sprite("#ship03.png");
this._ship.runAction(cc.moveBy(2, cc.p(Math.random() * winSize.width, this._ship.y + winSize.height + 100))); // js数组
http://www.w3school.com.cn/jsref/jsref_obj_array.asp
// js Boolean 对象
http://www.w3school.com.cn/jsref/jsref_obj_boolean.asp // this指针
//关于Javascript的this指针,和C++/Java很类似。我们来看个示例:(这个示例很简单了,我就不多说了) function print(text){
document.write(this.value + ' - ' + text+ '<br>');
//这里的this是调用print函数的对象
} var a = {value: 10, print : print};
var b = {value: 20, print : print}; print('hello');// this => global, output "undefined - hello" a.print('a');// this => a, output "10 - a"
b.print('b'); // this => b, output "20 - b" a['print']('a'); // this => a, output "10 - a"
http://www.php100.com/html/webkaifa/javascript/2012/0228/9927.html
http://www.ibm.com/developerworks/cn/web/1304_zengyz_jsoo/
js笔记--1的更多相关文章
- Data Visualization and D3.js 笔记(1)
课程地址: https://classroom.udacity.com/courses/ud507 什么是数据可视化? 高效传达一个故事/概念,探索数据的pattern 通过颜色.尺寸.形式在视觉上表 ...
- js笔记-0
#js笔记-0 数组: indexOf方法: Array也可以通过indexOf()来搜索一个指定的元素的位置: var arr = [10, 20, '30', 'xyz']; arr.indexO ...
- PPK谈JS笔记第一弹
以下内容是读书笔记,再一次温习JS好书:PPK谈JS window.load=initializePageaddEventSimple('window','load',function(){}) lo ...
- 面向小白的JS笔记 - #Codecademy#学习笔记
前言 最初浏览过<JavaScript秘密花园>,前一段时间读过一点点<JavaScript语言精粹>和一点点<JavaScript高级程序设计>(一点点是指都只是 ...
- require.js笔记
笔记参考来源:阮一峰 http://www.ruanyifeng.com/blog/2012/10/javascript_module.html 1. 浏览器端的模块只能采用“异步加载”方式 = ...
- JS笔记 入门第四
小测试: 注意:取消所有的设定可以直接使用 document.getElementById("txt").removeAttribute("style"); 这 ...
- JS笔记 入门第二
输出内容 document.write(); alert("hello!"); alert(mynum); </script> 注:alert弹出消息对话框(包含一个确 ...
- Node.js笔记1
Node.js入门笔记 1. node -help 可以显示帮助信息2. node REPL 模式(Read-eval-print loop) 输入—求值—输出循环 直接在cmd输入node 可以进入 ...
- JS笔记 入门第一
WHY? 一.你知道,为什么JavaScript非常值得我们学习吗? 1. 所有主流浏览器都支持JavaScript. 2. 目前,全世界大部分网页都使用JavaScript. 3. 它可以让网页呈现 ...
- 奇舞js笔记——第0课——如何写好原生js代码
摘要 1.好的代码职责要清晰,javscript不要用来操作样式: 2.API要设计的合理:通用性,适度的抽象(数据抽象,过程抽象),可扩展性: 3.效率问题:用好的.合适的算法(前端程序员要把自己当 ...
随机推荐
- js-特效部分学习-拖拽效果
一.客户区大小ClientWidth和ClientHeight <style> #box { width: 200px; height: 200px; background-color: ...
- mysql数据库查询pdo的用法
最早的php对mysql数据库查询是mysql和mysqli方法,后来php的新版本进一步封住了该方法,于是又pdo,抛开php框架,使用pdo查询数据,使用也是相当简便 <?php ini_s ...
- onSaveInstanceState & onRestoreInstanceState
一.onSaveInstanceState Called to retrieve per-instance state from an activity before being killed so ...
- [C++]项目中的代码注释规范(整理)
原文:http://blog.csdn.net/pleasecallmewhy/article/details/8658795 1 源文件头部注释 列出:版权.作者.编写日期和描述. 每行不要超过80 ...
- swoole 安装
swoole 安装: 1. 下载源代码,我下载的是1.8.6版本wget https://github.com/swoole/swoole-src/archive/1.8.6-stable.tar.g ...
- MD5的使用
/******************************************************************************* * keyBean 类实现了RSA D ...
- 个性二维码开源专题<基础篇>
二维码原理介绍: 二维码为什么是黑白相间的?黑色表示二进制的“1”,白色表示二进制的“0” “我们之所以对二维码进行扫描能读出那么多信息,就是因为这些信息被编入了二维码之中.”黄海平说,“制作二维码输 ...
- 从源代码分析Android-Universal-Image-Loader的缓存处理机制
讲到缓存,平时流水线上的码农一定觉得这是一个高大上的东西.看过网上各种讲缓存原理的文章,总感觉那些文章讲的就是玩具,能用吗?这次我将带你一起看过UIL这个国内外大牛都追捧的图片缓存类库的缓存处理机制. ...
- [ucgui] 对话框1——创建对话框
>_<" 小工具和对话框的区别: 小工具可以创建并独立使用,因为它们本质上就是窗口.但是,通常需要使用对话框,它是包含一个或多个小工具的窗口. 对话框通常是一个窗口,它在出现时会 ...
- tomcat安全配置
1. 注释或删除 tomcat-users.xml 所有用户权限,看上去如下: <tomcat-users></tomcat-users> 2. 隐藏tomcat版本信息 1 ...