近期有一个游戏叫围住神经猫,报道说是使用html5技术来做的。 html5的跨平台的优良特性非常不错。对于人手不足,技术不足,选用html5技术实现跨平台的梦想真是不错。

近期在看coco2d-js这个跨平台游戏开发框架。非常不错,写了一个demo程序供大家參考。

/**
* Created by caicai on 14-7-27.
*/
var Ball = cc.Sprite.extend({
velocity:null,
ctor:function () {
this._super(res.Ball_png);
var size = cc.director.getWinSize();
this.x = size.width/2;
this.y = size.height/2; this.velocity = cc.p(10,10);
},
update:function(dt){
this.setPosition(cc.pAdd(this.getPosition(), cc.pMult(this.velocity, dt)));
this.checkHitEdge();
},
checkHitEdge: function() {
var pos = this.getPosition();
var winSize = cc.director.getWinSize(); if (pos.x > winSize.width - this.width || pos.x < this.width) {
this.velocity.x *= -1;
} else if (pos.y > winSize.height - this.height || pos.y < this.height) {
this.velocity.y *= -1;
}
}
}); var GameLayer = cc.Layer.extend({
_ball:null,
_touchBeginAt: null,
ctor:function () {
this._super(); this._ball = new Ball();
this.addChild(this._ball); cc.eventManager.addListener({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: this.onTouchBegan,
onTouchMoved: this.onTouchMoved,
onTouchEnded: this.onTouchEnded
}, this); this.scheduleUpdate();
return true;
}, update:function(dt){
this._ball.update(dt);
}, onTouchBegan:function(touch, event) {
this._touchBeginAt = touch.getLocation();
console.log("begin")
return true;
}, onTouchMoved:function(touch, event) {
}, onTouchEnded:function(touch, event) {
console.log("end")
var endAt = touch.getLocation();
if(this._touchBeginAt == null) return true;
var velocity = cc.pSub(endAt, this._touchBeginAt);
event.getCurrentTarget()._ball.velocity = velocity;
return true;
} }); var BallScene = cc.Scene.extend({
layer:null,
onEnter:function () {
this._super();
this.layer = new GameLayer();
this.addChild(this.layer); this.schedule(this.update, 0); },
update: function(dt){
this.layer.update(dt);
} });

眼下还不完好,还有改进空间。

coco2d-js demo程序之滚动的小球的更多相关文章

  1. 微信小程序-通知滚动小提示

    代码地址如下:http://www.demodashi.com/demo/14044.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...

  2. js文字展示各种滚动效果

    js文字展示各种滚动效果:http://www.dowebok.com/demo/188/

  3. RCF进程间通信Demo程序

    在上一篇文章RPC通信框架--RCF介绍中,介绍了RCF的优点,本篇文章从头开始演示如何用RCF编写一个跨进程通信的Demo程序. 将RCF编译为静态库 从官网下载到的源码中包含一个RCF的项目,但是 ...

  4. Sequence.js 实现带有视差滚动特效的图片滑块

    Sequence.js 功能齐全,除了能实现之前分享过的现代的图片滑动效果,还可以融合当前非常流行的视差滚动(Parallax Scrolling)效果.让多层背景以不同的速度移动,形成立体的运动效果 ...

  5. Js倒计时程序

    Js倒计时程序 点击下载

  6. js点击左右滚动+默认自动滚动类

    js点击左右滚动+默认自动滚动类 点击下载

  7. js 实现单行文本滚动效果

    js 代码如下: /***************滚动场次开始*****************/ function ScrollText(content, btnPrevious, btnNext, ...

  8. js 实现文字列表滚动效果

    今天要实现抽奖名单在首页滚动展示的效果,就用js写了一个,代码如下: html代码: <style type="text/css"> *{margin:;padding ...

  9. c# winform 点菜宝接口demo程序

    前几天写了一篇关于c#调用 win32API的文章,有同学对点菜宝接口感兴趣,所以就把写的demo程序共享出来,大家一起讨论改进,so放百度云地址: 百度云下载地址

随机推荐

  1. python之操作excel:xlrd、xlwt、xlutiles、枚举函数enumerate()

    一.读excel: xlrd-----只能读.不能写 import xlrd book=xlrd.open_workbook(r'E:\BestTest\内容\名单.xlsx') #打开excel s ...

  2. 02numpy

    一. Numpy定义 一个在Python中做科学计算的基础库,重在数值计算,也是大部分PYTHON科学计算库的基础库,多用于在大型.多维数组上执行数值运算 二. Numpy使用 1.创建数组 2.nu ...

  3. Shell替换数组元素之间的间隔符号

    Shell中的数组是这样表示的: arr=(1,2,3,4,5) 它们数组元素的间隔符号为逗号,如果我相把逗号替换为加号: echo ${arr//,/+} 输出: 1+2+3+4+5 这个表达式是我 ...

  4. ubuntu中执行docker info出现警告信息WARNING: No memory limit support 或 WARNING: No swap limit support

    docker info 指令报若下错误:WARNING: No memory limit support 或WARNING: No swap limit support 解决方法: 1.打开/etc/ ...

  5. Shell流程语句

    1. shell流程控制 流程控制是改变程序运行顺序的指令.linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case). 2. if ...

  6. c++_凑算式(最新方法)

    凑算式 B DEFA + --- + ------- = 10 C GHI (如果显示有问题,可以参见[图1.jpg]) 这个算式中A~I代表1~9的数字,不同的字母代表不同的数字. 比如:6+8/3 ...

  7. PHP 配置文件php.ini文件优化

    PHP 5.3.3 safe_mode = On #控制php中的函数执行比如system() 这个函数可以调用系统目录 比如 rm ,打开这个配置之后,同时把很多文件操作的函数进行了权限控制 saf ...

  8. Python面向对象之文件操作

    文件的概念 文件的概念和作用 计算机的文件,就是存储在某种长期存储设备上的一段数据:长期存储设备包括:U盘,硬盘,移动硬盘,光盘,等: 文件的作用:将数据长期保存,在需要的时候使用: 文件的存储方式 ...

  9. finally块的问题(finally block does not complete normally)

    http://blog.csdn.net/chh_jiang/article/details/4557461 当finall块中包含return语句时,Eclipse会给出警告“finally blo ...

  10. mybatis动态sql foreach的用法

    <select id="findUserByIds" parameterType="com.pojo.QueryVo" resultType=" ...