重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
var WINDOW_WIDTH = 480.0;
成都一家集口碑和实力的网站建设服务商,拥有专业的企业建站团队和靠谱的建站技术,10多年企业及个人网站建设经验 ,为成都近1000家客户提供网页设计制作,网站开发,企业网站制作建设等服务,包括成都营销型网站建设,成都品牌网站建设,同时也为不同行业的客户提供成都做网站、网站设计的服务,包括成都电商型网站制作建设,装修行业网站制作建设,传统机械行业网站建设,传统农业行业网站制作建设。在成都做网站,选网站制作建设服务商就选创新互联公司。
var WINDOW_HEIGHT = 320.0;
var TOUCH_DELTA = 5;
var ScrollView = cc.Layer.extend({
//按下点
m_TouchDownPoint:0,
//抬起点
m_TouchUpPoint:0,
//当前触摸点
m_TouchCurPoint:0,
//总页数
m_Page:0,
//当前显示页数
m_CurPage:0,
//存储所有的页层
m_PageLayer:[],
ctor:function(){
this._super();
cc.Director.getInstance().getTouchDispatcher().addTargetedDelegate(this,0,true);
this.isTouchEnabled();
},
//跳转页
goToPage:function(){
var moveTo = cc.MoveTo.create(0.2, cc.PointMake(-this.m_CurPage * WINDOW_WIDTH, 0));
this.runAction(moveTo);
},
// 触摸事件相关
onTouchBegan:function(touch, event){
this.m_TouchDownPoint = touch.getLocation();
this.m_TouchCurPoint = this.m_TouchDownPoint;
return true;
},
onTouchMoved:function(touch, event){
var touchPoint = touch.getLocation();
var posPoint = cc.PointMake(this.getPositionX() + touchPoint.x - this.m_TouchCurPoint.x,this.getPositionY());
this.setPosition(posPoint);
this.m_TouchCurPoint = touchPoint;
},
onTouchEnded:function(touch, event){
this.m_TouchUpPoint = touch.getLocation();
// 计算按下和抬起的偏移量
var offset = (this.m_TouchUpPoint.x - this.m_TouchDownPoint.x) * (this.m_TouchUpPoint.x - this.m_TouchDownPoint.x) + (this.m_TouchUpPoint.y - this.m_TouchDownPoint.y) * (this.m_TouchUpPoint.y - this.m_TouchDownPoint.y);
if (offset < (TOUCH_DELTA * TOUCH_DELTA)) {
// 点击
// 向子Layer发送Click消息
this.m_PageLayer[this.m_CurPage].onTouchBegan(touch,event);
}
else {
// 滑动结束
var offset = this.getPositionX() - this.m_CurPage * (-WINDOW_WIDTH);
if (offset > WINDOW_WIDTH / 2) {
// 上一页
if (this.m_CurPage > 0) {
--this.m_CurPage;
cc.log("I am :"+this.m_CurPage);
}
}
else if (offset < -WINDOW_WIDTH / 2) {
// 下一页
if (this.m_CurPage < (this.m_Page - 1)) {
++this.m_CurPage;
cc.log("I am :"+this.m_CurPage);
}
}
// 执行跳转动画
this.goToPage();
}
},
//添加页
addPage:function(pPageLayer){
if (pPageLayer) {
// 设置成一页大小
pPageLayer.setContentSize(cc.SizeMake(WINDOW_WIDTH, WINDOW_HEIGHT));
pPageLayer.setPosition(cc.p(WINDOW_WIDTH * this.m_Page, 0));
this.addChild(pPageLayer);
// 添加到页
this.m_PageLayer.push(pPageLayer);
this.m_Page = this.m_PageLayer.length;
}
}
});
//在2.2里运行有BUG···以后在做修改吧····