//因为方向是从上往下,如果container高度超出,则需要设置初始位移 var delta = scrollHeight - containerHeight; if (delta < 0) { scrollView.setContentOffset(cc.p(0, delta), false) }
for (var i = 0; i < cellcount; i++) { var s1 = new cc.Sprite("#hall_enter_" + i + ".png"); var posx = i % 2 == 0 ? w * 0.25 : w * 0.75; var posy = containerHeight - (Math.floor(i / 2) + 0.5) * cellheight; s1.setPosition(posx, posy); container.addChild(s1); } container.bake();
var bTouchCanceled = false; var touchBeganPos = cc.p(0, 0); var that = this; cc.eventManager.addListener({ event: cc.EventListener.TOUCH_ONE_BY_ONE, swallowTouches: false, onTouchBegan: function(touch, event) { var bounding = scrollView.getBoundingBox(); var pos = touch.getLocation(); if (cc.rectContainsPoint(bounding, pos)) { bTouchCanceled = false; touchBeganPos = pos; return true; } return false; }, onTouchEnded: function(touch, event) { if (bTouchCanceled) { return; } var loc = container.convertToNodeSpace(touch.getLocation()); var col = loc.x < w * 0.5 ? 0 : 1; var row = Math.floor((containerHeight - loc.y) / cellheight); var index = 2 * row + col; that.onCellNodeClick(index); }, onTouchCancelled: function() { bTouchCanceled = true; },
onTouchMoved: function(touch, event) { var loc = touch.getLocation(); if (Math.abs(loc.x - touchBeganPos.x) > 10 || Math.abs(loc.y - touchBeganPos.y) > 10) { bTouchCanceled = true; } } }, container);