var HelloWorldLayer = cc.Layer.extend({
_bg1: null,
_bg2: null,
_bg3: null,
_bg: null,
_size: null,
ctor: function () {
this._super();
this._size = cc.winSize;
this._bg = new cc.ParallaxNode();
this._bg1 = new cc.Sprite(res.bg1_png);
this._bg2 = new cc.Sprite(res.bg2_png);
this._bg.addChild(this._bg1, 3, cc.p(0.5, 0), cc.p(this._bg1.width / 2, this._bg1.height / 2));
this._bg.addChild(this._bg2, 2, cc.p(1.3, 0), cc.p(this._bg2.width / 2, this._bg2.height / 2));
this.addChild(this._bg);
//滑动侦听
var listener = cc.EventListener.create({
event: cc.EventListener.TOUCH_ONE_BY_ONE,
swallowTouches: true,
onTouchBegan: function (touch, event) {
return true;
},
onTouchMoved: function (touch, event) {
var target = event.getCurrentTarget();
var delta = touch.getDelta();
// 移动当前按钮精灵的坐标位置
这里我想判断视觉移动不要让图片超出屏幕边界怎么判断啊,想到我头大了,求高人指点
this._bg.setPositionX(this._bg.getPositionX()+delta.x);
}.bind(this),
onTouchEnded: function (touch, event) { // 点击事件结束处理
}.bind(this)
});
// 注册监听器
cc.eventManager.addListener(listener, this._bg);
return true;
}
});
var HelloWorldScene = cc.Scene.extend({
onEnter: function () {
this._super();
var layer = new HelloWorldLayer();
this.addChild(layer);
}
});
```
跪求高人指点,我是小白,初学的
哎,算了,我解决了,结贴了