0

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

  • Taken a scroll view of width: 300, height: 320 with Horizontal scrolling enabled and Bounces enabled.
  • Select Content node as PlayerList.ccb (Thus needs to create another PlayerList.ccb class)

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 ?

Paresh Thakor
  • 1,795
  • 2
  • 27
  • 47
  • I have not been following lately, but if I recall, at one point, it was best to harness the scrollview in `onEnter` because `didLoadFromCCB` occurs before the contentSizes are set properly (when they are added to a parent and run through their `onEnter`). – YvesLeBorg Jan 10 '16 at 23:04
  • @YvesLeBorg I tried loading all playerBoxes inside onEnter method. but it seems to me that didLoadFromCCB() is called before onEnter. and the code did not work by the way. Can you please suggest me some tutorials or examples? – Paresh Thakor Jan 11 '16 at 17:48

0 Answers0