近期有一个游戏叫围住神经猫,报道说是使用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. CreateProcess Access violation(越界访问)

    https://stackoverflow.com/questions/11339186/createprocess-fails-with-an-access-violation My aim is ...

  2. html自动刷新

    头部<meta http-equiv="refresh" content="10"> 或者js实现 <script language=&quo ...

  3. Manjaro安装SS客户端

    首先安装shadowsocks-libev sudo pacman -S shadowsocks-libev 然后编辑配置文件 vim /etc/shadowsocks/config.json { & ...

  4. 条款13:以对象管理资源(use objects to manage resources)

    NOTE: 1.为防止资源泄漏,请使用RAII对象,它们在构造函数中获得资源并在析构函数中释放资源. 2.两个常被使用的RAII classes 分别是 trl::shared_ptr 和 auto_ ...

  5. Python能干啥?

    Python之py9 Python之py9-录音自动下载 Python之py9-py9作业检查 Python之py9-py9博客情况获取 Python之py9-微信监控获取mp3_url Python ...

  6. nginx.conf的完整配置说明

    #用户 用户组 user www www; #工作进程,根据硬件调整,有人说几核cpu,就配几个,我觉得可以多一点 worker_processes 5: #错误日志 error_log logs/e ...

  7. angularjs ng-repeat下验证问题

    angularjs验证要求name唯一,repeat情况,name 等通过${index}等绑定,也无法获取值 通过ng-from的方法,这样验证name重复也可以了. <ng-form nam ...

  8. winform中ComboBox控件的简单使用

    在开发winform中用到了ComboBox,但是发现和asp.net中的DropDownList差别比我想象中的大. 给ComboBox添加数据总结的有两种方法(绑定数据库在这里不说): 第一种方法 ...

  9. BNUOJ 1575 Supermarket

    Supermarket Time Limit: 2000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID ...

  10. 使用 wsgiref 创建WSGI APP

    wsgify装饰器将一个普通函数转变成WSGI应用程序. class webob.dec.wsgify(func=None, RequestClass=None, args=(), kwargs=No ...