前端之家收集整理的这篇文章主要介绍了
cocos2d-js scrollview 例子,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
var HelloWorldLayer = cc.Layer.extend({
sprite: null,ctor: function () {
this._super()
var size = cc.winSize
var listView = new ccui.ScrollView()
listView.setDirection(ccui.ScrollView.DIR_HORIZONTAL)
listView.setTouchEnabled(true)
listView.setBounceEnabled(true)
listView.setSize(cc.size(512,200))
listView.x = size.width / 2
listView.y = size.height / 2
listView.setAnchorPoint(cc.p(0.5,0.5))
this.addChild(listView)
listView.setInnerContainerSize(cc.size(128 * 6,200))
for (var i = 0
var sprite = new cc.Sprite(res.item_png)
listView.addChild(sprite)
sprite.x = i * 130 + 40
sprite.y = listView.getInnerContainerSize().height / 2
sprite.setAnchorPoint(cc.p(0.5,0.5))
}
listView.jumpToLeft()
cc.log("ben guo...")
return true
}
})
var HelloWorldScene = cc.Scene.extend({
onEnter: function () {
this._super()
var layer = new HelloWorldLayer()
this.addChild(layer)
}
})