coco2d-js demo程序之滚动的小球
2017-07-11 16:57
369 查看
近期有一个游戏叫围住神经猫,报道说是使用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简单小程序练习-排行榜文字向上滚动
- 一键搭建微信小程序开发环境 及demo运行(腾讯云上一键搭建node.js服务器环境,PHP,Java,.NET服务类似)
- coco2d-js在HTML上可以运行,但是打包apk后会黑屏
- 编译Coco2d-x android 程序出现make: *** No rule to make target ...CCConfiguration.o'. Stop.
- 编译Coco2d-x android 程序出现make: *** No rule to make target ...CCConfiguration.o'. Stop.
- [MFC]ScrollDemo程序:CScrollView滚动视图的应用
- coco2d-x 交叉编译成Android程序及中间遇到的问题
- 解决Android客户端运行Cococs2dx编写的游戏程序遇到的意外游戏中断导致的游戏黑屏问题
- coco2d-js 无法加载网络图片(Failed to execute 'texImage2D' on ‘WebGLRenderin
- Cocos2d-x:编译Coco2d-x android 程序出现make: *** No rule to make target ...CC*.o'. Stop.
- H5 2D渲染引擎—Pixi.js简介及小demo
- coco2d-js 触摸移动的同时处理点击事件
- 编写程序实现demo.exe演示笑脸小球运动效果
- [JS效果]无间断滚动程序
- Coco2d-x 3.X 点击滚动、移动滚动
- cocos2d-x-3.1 win32程序-初识源码(coco2d-x 学习笔记二)
- 小程序浮层滚动阻止window窗体滚动JS/CSS处理
- 一些Coco2d-js笔记
- coco2d js 修改预加载,使用自定义图片