Paresh Thakor
Paresh Thakor

Reputation: 1835

CCScrollview not working

I am using Sprite Builder and created a scrollview to create selection of players list in stripe which can be scrolled horizontally.

PlayerListContainer.ccb:Scrollview Container

PlayerListContainer.swift - noting major but just call back functions are called.

PlayerList.ccb : Main listing - Take CCNode with width, height as 300,320 PlayerList.swift

//
//  PlayerList.swift
//  tsb
//
//  Created by Paresh Thakor on 27/12/15.
//  Copyright (c) 2015 Apportable. All rights reserved.
//

import Foundation

//let Pi = CGFloat(M_PI)
//let degreesToRadians = CGFloat(Pi / 180)
//let radiansToDegrees = CGFloat(180 / Pi)

class PlayerList: CCNode {
    //weak var __horizontalLayout: CCLayoutBox!
    //weak var __container: CCScrollView!
    weak var __node: CCNode!
    var userDefaults = NSUserDefaults.standardUserDefaults()

    override init!() {
        super.init()
        NSLog("init Player list")
    }

    func didLoadFromCCB() {
        NSLog("Player list loaded")

        __node.contentSizeType = CCSizeTypeNormalized
        //__node.contentSizeInPoints = CGSizeMake(1000, 500)
        __node.contentSize = CGSizeMake(3, 1)

        // Add player children to select
        for (var i = 0; i<20; i++) {   
            let playerBox = CCNodeColor(color: CCColor.redColor())
            //playerBox.contentSize = CGSizeMake(50, 50)

            let player = CCSprite(imageNamed: "ccbResources/playerBall.png")
            playerBox.contentSize = CGSizeMake(player.contentSizeInPoints.width+20, player.contentSizeInPoints.height+20)
            playerBox.position = ccp(CGFloat(5)+((playerBox.contentSizeInPoints.width+CGFloat(5)) * CGFloat(i)),5)

            player.position = ccp(playerBox.contentSizeInPoints.width/2, playerBox.contentSizeInPoints.height/2)
            playerBox.addChild(player)

            __node.addChild(playerBox)
        }

        //self.contentSizeInPoints = CGSizeMake(20*50, 50)
        self.userInteractionEnabled = true
        self.color = CCColor(UIColor: UIColor.greenColor())
    }
}

This works but the scrollview is not being displayed. this will load infinite boxes which we placed.

This scrollview does not scroll to right, etc. nothing happens.

Can some one tell me ?

Upvotes: 0

Views: 74

Answers (0)

Related Questions