coco2d-js demo程序之滚动的小球
近期有一个游戏叫围住神经猫,报道说是使用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程序之滚动的小球的更多相关文章
- 微信小程序-通知滚动小提示
代码地址如下:http://www.demodashi.com/demo/14044.html 一.前期准备工作 软件环境:微信开发者工具 官方下载地址:https://mp.weixin.qq.co ...
- js文字展示各种滚动效果
js文字展示各种滚动效果:http://www.dowebok.com/demo/188/
- RCF进程间通信Demo程序
在上一篇文章RPC通信框架--RCF介绍中,介绍了RCF的优点,本篇文章从头开始演示如何用RCF编写一个跨进程通信的Demo程序. 将RCF编译为静态库 从官网下载到的源码中包含一个RCF的项目,但是 ...
- Sequence.js 实现带有视差滚动特效的图片滑块
Sequence.js 功能齐全,除了能实现之前分享过的现代的图片滑动效果,还可以融合当前非常流行的视差滚动(Parallax Scrolling)效果.让多层背景以不同的速度移动,形成立体的运动效果 ...
- Js倒计时程序
Js倒计时程序 点击下载
- js点击左右滚动+默认自动滚动类
js点击左右滚动+默认自动滚动类 点击下载
- js 实现单行文本滚动效果
js 代码如下: /***************滚动场次开始*****************/ function ScrollText(content, btnPrevious, btnNext, ...
- js 实现文字列表滚动效果
今天要实现抽奖名单在首页滚动展示的效果,就用js写了一个,代码如下: html代码: <style type="text/css"> *{margin:;padding ...
- c# winform 点菜宝接口demo程序
前几天写了一篇关于c#调用 win32API的文章,有同学对点菜宝接口感兴趣,所以就把写的demo程序共享出来,大家一起讨论改进,so放百度云地址: 百度云下载地址
随机推荐
- python:第一章
完成同一个任务,C语言要写1000行代码,Java只需要写100行,而Python可能只要20行. 代码少的代价是运行速度慢,C程序运行1秒钟,Java程序可能需要2秒,而Python程序可能就需要1 ...
- linux 05
日期与时间命令:date.日历的命令:cal.计算器:bc 要使用quit退出 在命令行模式里执行命令时,会有两种主要情况: 一种是该命令会直接显示结果然后回到命令提示符等待下一个命令的输入 dat ...
- ubuntu卸载编译安装的软件
cd 源代码目录 make clean ./configure make make uninstall
- 05 selenium模块
selenium模块 selenium selenium是Python的一个第三方库,对外提供的接口可以操作浏览器,然后让浏览器完成自动化的操作. selenium最初是一个自动化测试工具,而爬虫中使 ...
- [第一波模拟\day2\T1] {病毒分裂}(split.cpp)
[题目描述] A 学校的实验室新研制出了一种十分厉害的病毒.由于这种病毒太难以人工制造了,所以专家们在一开始只做出了一个这样的病毒.这个病毒被植入了特殊的微型芯片,使其可以具有一些可编程的特殊性能.最 ...
- Golang 编写 Tcp 服务器
Golang 作为广泛用于服务端和云计算领域的编程语言,tcp socket 是其中至关重要的功能.无论是 WEB 服务器还是各类中间件都离不开 tcp socket 的支持. Echo 服务器 拆包 ...
- maven+Spring环境搭建
一,项目结构图 二,applicationContext.xml <?xml version="1.0" encoding="UTF-8"?> &l ...
- 尼姆博弈扩展形式(一): 限定每次取物的上限。NYOJ-135,难度5~~~
取石子(二) 时间限制:3000 ms | 内存限制:65535 KB 难度:5 http://acm.nyist.net/JudgeOnline/problem.php?pid=135 描述 小 ...
- HDU-1858-Max Partial Value I,有坑点,不难;
Max Partial Value I Time Limit: 1000/5000 MS (Java/Others) Memory Limit: 32768/65535 K (Java/Othe ...
- POJ 2352 star level
题目链接: http://poj.org/problem?id=2352 题目大意:对于每一颗星星来说,都有一个属于自己的level,这个值为其他星星x,y坐标均不大于本星星的个数.输入时按先y由小到 ...