var AnimationLayer = cc.Layer.extend({
ctor:function (space) {
this._super();
this.space = space;
this.init();
this._debugNode = new cc.PhysicsDebugNode(this.space);
this._debugNode.setVisible(false);
// Parallax ratio and offset
this.addChild(this._debugNode, 10);
},
init:function (){
this._super();
this.MySquare = cc.PhysicsSprite.create(res.MySquare1_png);
this.body = new cp.Body(1, cp.momentForBox(0.01, 600, 0));
this.body.setPos(cc.p(50, 300));
this.schedule(function(){
this.body.applyImpulse(cp.v(10, 0), cp.v(0, 0));
}, 0.1);
this.space.addBody(this.body);
var shape = new cp.BoxShape(this.body, this.MySquare.getContentSize().width, this.MySquare.getContentSize().height);
shape.setCollisionType(1);
this.space.addShape(shape);
this.MySquare.setBody(this.body);
this.addChild(this.MySquare, 10, 1);
},
getEyeX:function () {
return this.MySquare.getPositionX() - g_runnerStartX;
}
})
```
var g_groundHeight = 57;
var g_runnerStartX = 80;
var HelloWorldLayer = cc.Scene.extend({
sprite:null,
onEnter:function () {
//////////////////////////////
// 1. super init first
this._super();
/////////////////////////////
// 2. add a menu item with "X" image, which is clicked to quit the program
// you may modify it.
// ask the window size
var size = cc.winSize;
this.initPhysics();
/*var followAction = cc.Follow.create(this.MySquare, cc.rect(0, 0, size.width*3, size.height));
this.runAction(followAction);*/
this.gameLayer = new cc.Layer();
this.gameLayer.addChild(new BackgroundLayer(this.space), 0, TagOfLayer.background);
this.gameLayer.addChild(new AnimationLayer(this.space), 0, TagOfLayer.Animation);
this.addChild(this.gameLayer);
this.scheduleUpdate();
// add a "close" icon to exit the progress. it's an autorelease object
return true;
},
initPhysics : function(){
this.space = new cp.Space();
this.space.gravity = cp.v(0, -350);
var wallBottom = new cp.SegmentShape(this.space.staticBody,
cp.v(0, g_groundHeight),// start point
cp.v(4294967295, 30),// MAX INT:4294967295
0);// thickness of wall
this.space.addStaticShape(wallBottom);
},
update:function (dt) {
// chipmunk step
this.space.step(dt);
var animationLayer = this.gameLayer.getChildByTag(TagOfLayer.Animation);
var eyeX = animationLayer.getEyeX();
this.gameLayer.setPosition(cc.p(-eyeX,0));
}
});
```
背景是可以向后面移动了,但主角的精灵还是飞出屏幕了,没有跟随,但官网下载的例子运行却是可以,我找不出有什么不同了,为什么还是不行?求大神
毫无头绪,能放些实力上来,学习学习吗