coco2d-js demo程序之滚动的小球
2014-07-27 21:22
357 查看
最近有一个游戏叫围住神经猫,报道说是使用html5技术来做的。 html5的跨平台的优良特性很不错,对于人手不足,技术不足,选用html5技术实现跨平台的梦想真是不错。
最近在看coco2d-js这个跨平台游戏开发框架,很不错,写了一个demo程序供大家参考。
目前还不完善,还有改进空间。
最近在看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程序之滚动的小球
- [JS效果]无间断滚动程序
- 编译Coco2d-x android 程序出现make: *** No rule to make target ...CCConfiguration.o'. Stop.
- [MFC]ScrollDemo程序:CScrollView滚动视图的应用
- 微信小程序demo:富文本解析,折线图,MD5,bluebird.js,es6
- Cocos2d-x:编译Coco2d-x android 程序出现make: *** No rule to make target ...CC*.o'. Stop.
- MSClass (Class Of Marquee Scroll通用不间断滚动JS封装类) Ver 1.65 程序制作/版权所有:崔永祥(333)
- 一些Coco2d-js笔记
- COCO2D-JS 笔记
- html中滚动小球的demo
- coco2d-x学习之程序入口
- coco2d-js 触摸移动的同时处理点击事件
- cocos2d-x-3.1 win32程序-初识源码(coco2d-x 学习笔记二)
- coco2d js 修改预加载,使用自定义图片
- java方式来写js程序(demo)
- 编写程序实现demo.exe演示笑脸小球运动效果
- 编译Coco2d-x android 程序出现make: *** No rule to make target ...CCConfiguration.o'. Stop
- 解决Android客户端运行Cococs2dx编写的游戏程序遇到的意外游戏中断导致的游戏黑屏问题
- Coco2d-x 3.X 点击滚动、移动滚动
- js实现数据流(日志流,报警信息等)滚动展示,并分页(含实现demo)