Permalink
Browse files

first commit

  • Loading branch information...
0 parents commit 7b89a16d10153d8bd48652a4bbfb961af81d88ab @akira-cn akira-cn committed Feb 13, 2014
@@ -0,0 +1 @@
+.DS_Store
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1 @@
+python -m SimpleHTTPServer
@@ -0,0 +1,6 @@
+{
+ baseUrl: ".",
+ name: "cqwrap/index",
+ out: "cqwrap-min.js",
+ removeCombined: true,
+}
@@ -0,0 +1,7 @@
+{
+ baseUrl: ".",
+ name: "./main-src",
+ out: "main.js",
+ removeCombined: true,
+ //exclude: [ "cqwrap/index.js" ]
+}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,51 @@
+(function(global){
+ /* define(function(require, exports, module){}) */
+ var _modCache = {};
+ var _moduleStack = [];
+
+ function _require(mod){
+
+ mod = mod.replace(/\.js$/, '');
+
+ if(!_modCache[mod]){
+ _moduleStack.push({exports:{}});
+ require(mod + '.js');
+ _modCache[mod] = module.exports;
+ _moduleStack.pop();
+ }
+
+ return _modCache[mod];
+ }
+
+ global.define = function(func){
+ var ret = func(_require, module.exports, module);
+ if(module.use <= 1){
+ module.exports = ret;
+ }
+ return ret;
+ }
+
+ Object.defineProperty(global, 'module', {
+ get: function(){
+ var module = _moduleStack[_moduleStack.length - 1];
+ module.use = module.use || 0;
+ module.use++;
+ return module;
+ },
+ enumerable: true,
+ configurable: false,
+ });
+
+ Object.defineProperty(global, 'exports', {
+ get: function(){
+ return module.exports;
+ },
+ enumerable: true,
+ configurable: false,
+ });
+
+ Object.defineProperty(global, '_require', {
+ value: _require,
+ });
+
+})(this);
@@ -0,0 +1,244 @@
+
+define(function(require, exports, module) {
+
+'use strict';
+
+var AnimationTool = {};
+
+var BaseSprite = require('cqwrap/sprites').BaseSprite;
+
+var getAnimFrames = function(name) {
+ var cache = cc.SpriteFrameCache.getInstance(),
+ frames = [],
+ i = 0;
+
+ do {
+ var frameName = name.replace('%d', i),
+ frame = cache.getSpriteFrame(frameName);
+
+ if(frame) {
+ frames.push(frame);
+ }else {
+ break;
+ }
+
+ } while (++i);
+
+ return frames;
+};
+
+//将PNG序列转成一次性动画
+AnimationTool.createAnimFromPng = function(name, delay) {
+ var frames = getAnimFrames(name),
+ animation = cc.Animation.create(frames, delay);
+
+ return cc.Animate.create(animation);
+};
+
+//将PNG序列转成永久性动画
+AnimationTool.createRFAnimFromPng = function(name, delay) {
+ return cc.RepeatForever.create(AnimationTool.createAnimFromPng(name, delay));
+};
+
+/**
+ var animSprite = new FrameAnimSprite('abc.png');
+ -> play abc0.png、abc1.png ... abcn.png
+ */
+var FrameAnimSprite = BaseSprite.extend({
+ init: function(img){
+ this._super();
+ this.img = img;
+ this.animate = null;
+ return true;
+ },
+ animate: function(delay, repeat){
+ if(!this.animate){
+ var img = this.img;
+ if(!/%d/.test(this.img)){
+ img = this.img.replace(/\./, '%d.');
+ }
+ var method = repeat? 'createRFAnimFromPng' : 'createAnimFromPng';
+ this.animate = AnimationTool[method](img, delay);
+ }
+ this.runAction(this.animate);
+ }
+});
+
+function AnimationTask(){}
+
+cc.mixin(AnimationTask.prototype, {
+ getActions: function(){
+ this._animSeq = this._animSeq || [];
+ return this._animSeq;
+ },
+ addAction: function(actionCls, args, easing, rate){
+ for(var i = args.length - 1; i >= 0; i--){
+ if(args[i] !== undefined){
+ //args.length = i + 1;
+ break;
+ }
+ }
+ args.length = i + 1;
+ var actions = [actionCls.create.apply(actionCls, args)];
+ if(easing){
+ //rate = rate || 2;
+ var easingArgs = [].slice.call(arguments, 3);
+ for(var i = easingArgs.length - 1; i >= 0; i--){
+ if(easingArgs[i] !== undefined){
+ //easingArgs.length = i + 1;
+ break;
+ }
+ }
+ easingArgs.length = i + 1;
+ //cc.log(i, easingArgs);
+ actions[0] = easing.create.apply(easing, [actions[0]].concat(easingArgs));
+ }
+ var actionSeq = this.getActions();
+ actionSeq.push.apply(actionSeq, actions);
+ return this;
+ },
+ clearActions: function(){
+ this.getActions().length = 0;
+ return this;
+ },
+ delay: function(time){
+ return this.addAction(cc.DelayTime, [time]);
+ },
+ repeat: function(times){
+ times = times || 9999999;
+ var actionSeq = this.getActions();
+ if(actionSeq.length > 0){
+ var action = actionSeq[actionSeq.length - 1];
+ action = cc.Repeat.create(action, times);
+ actionSeq[actionSeq.length - 1] = action;
+ }
+ return this;
+ },
+ repeatAll: function(times){
+ times = times || 9999999;
+ var actionSeq = this.getActions();
+ if(actionSeq.length > 0){
+ var action = cc.Sequence.create.apply(cc.Sequence, actionSeq);
+ action = cc.Repeat.create(action, times);
+ actionSeq.length = 0;
+ actionSeq.push(action);
+ }
+ return this;
+ },
+ reverse: function(){
+ var actionSeq = this.getActions();
+ if(actionSeq.length > 0){
+ var action = actionSeq[actionSeq.length - 1];
+ actionSeq.push(action.reverse());
+ }
+ return this;
+ },
+ reverseAll: function(){
+ var actionSeq = this.getActions();
+ if(actionSeq.length > 0){
+ var action = cc.Sequence.create.apply(cc.Sequence, actionSeq);
+ actionSeq.push(action.reverse());
+ }
+ return this;
+ },
+ then: function(callback){
+ callback = cc.CallFunc.create(callback, this);
+ this.getActions().push(callback);
+ return this;
+ },
+
+ /**
+ sprite.animate(0.2, 'a.png', 'b.png', 'c.png');
+ sprite.animate(0.2, 'abc_%d.png');
+ */
+ animate: function(delay /* frames */){
+ var frames = [].slice.call(arguments, 1);
+
+ if(/%d/.test(frames[0])){
+ frames = getAnimFrames(frames[0]);
+ }else{
+ var cache = cc.SpriteFrameCache.getInstance();
+ frames = frames.map(function(frameName){
+ return cache.getSpriteFrame(frameName);
+ });
+ }
+
+ var animation = cc.Animation.create(frames, delay/frames.length);
+ this.getActions().push(cc.Animate.create(animation));
+ return this;
+ },
+ bezierBy: function(dur, conf, easing, rate){
+ return this.addAction(cc.BezierBy, [dur, conf], easing, rate);
+ },
+ bezierTo: function(dur, conf, easing, rate){
+ return this.addAction(cc.BezierTo, [dur, conf], easing, rate);
+ },
+ blink: function(dur, blinks, easing, rate){
+ return this.addAction(cc.Blink, [dur, blinks], easing, rate);
+ },
+ fadeIn: function(dur, easing, rate){
+ return this.addAction(cc.FadeIn, [dur], easing, rate);
+ },
+ fadeOut: function(dur, easing, rate){
+ return this.addAction(cc.FadeOut, [dur], easing, rate);
+ },
+ fadeTo: function(dur, opacity, easing, rate){
+ return this.addAction(cc.FadeTo, [dur, opacity], easing, rate);
+ },
+ jumpBy: function(dur, pos, height, times, easing, rate){
+ return this.runAction(cc.JumpBy, [dur, pos, height, times || 1], easing, rate);
+ },
+ jumpTo: function(dur, pos, height, times, easing, rate){
+ return this.runAction(cc.JumpTo, [dur, pos, height, times || 1], easing, rate);
+ },
+ moveBy: function(dur, pos, easing, rate){
+ return this.addAction(cc.MoveBy, [dur, pos], easing, rate);
+ },
+ moveTo: function(dur, pos, easing, rate){
+ return this.addAction(cc.MoveTo, [dur, pos], easing, rate);
+ },
+ rotateBy: function(dur, deltaX, deltaY, easing, rate){
+ return this.addAction(cc.RotateBy, [dur, deltaX, deltaY], easing, rate);
+ },
+ rotateTo: function(dur, deltaX, deltaY, easing, rate){
+ return this.addAction(cc.RotateTo, [dur, deltaX, deltaY], easing, rate);
+ },
+ scaleBy: function(dur, sx, sy, easing, rate){
+ return this.addAction(cc.ScaleBy, [dur, sx, sy], easing, rate);
+ },
+ scaleTo: function(dur, sx, sy, easing, rate){
+ return this.addAction(cc.ScaleTo, [dur, sx, sy], easing, rate);
+ },
+ skewBy: function(dur, sx, sy, easing, rate){
+ return this.addAction(cc.SkewBy, [dur, sx, sy], easing, rate);
+ },
+ skewTo: function(dur, sx, sy, easing, rate){
+ return this.addAction(cc.SkewTo, [dur, sx, sy], easing, rate);
+ },
+ tineBy: function(dur, deltaR, deltaG, deltaB, easing, rate){
+ return this.addAction(cc.TineBy, [dur, deltaR, deltaG, deltaB], easing, rate);
+ },
+ tineTo: function(dur, deltaR, deltaG, deltaB, easing, rate){
+ return this.addAction(cc.TineTo, [dur, deltaR, deltaG, deltaB], easing, rate);
+ }
+});
+
+cc.Node.prototype.act = function(task){
+ var actionSeq = task ? task.getActions() : this.getActions();
+ if(actionSeq.length > 0){
+ var action = cc.Sequence.create.apply(cc.Sequence, actionSeq);
+ this.runAction(action);
+ if(!task) this.clearActions();
+ }
+ return this;
+}
+
+cc.mixin(cc.Node.prototype, new AnimationTask());
+
+
+module.exports = {
+ AnimationTool: AnimationTool,
+ FrameAnimSprite: FrameAnimSprite,
+ AnimationTask: AnimationTask
+}
+});
@@ -0,0 +1,34 @@
+define(function(require, exports, module){
+
+var audio = cc.AudioEngine.getInstance();
+var audio_enable = {effect: true, music: true};
+
+var Audio = {
+ playEffect: function(name){
+ if(audio_enable.effect){
+ audio.playEffect(name, false);
+ }
+ },
+ playMusic: function(name){
+ if(audio_enable.music){
+ audio.playMusic(name, true);
+ }
+ },
+ pauseMusic: function(){
+ audio.pauseMusic();
+ },
+ resumeMusic: function(){
+ audio.resumeMusic();
+ },
+ setEnable: function(enable){
+ if(typeof enable !== 'object'){
+ enable = {effect: enable, music: enable};
+ }
+
+ audio_enable = enable;
+ }
+};
+
+module.exports = Audio;
+
+});
Oops, something went wrong.

0 comments on commit 7b89a16

Please sign in to comment.