is it possible to implement iCarousel with SKScene array?

193 views Asked by At

I'm working on project and I want to create iCarousel that contains different scenes details. To be clear, My app save arenas with their contents in XML files from SKScene, and I want to have a previews of all the arenas before I load them. and thought that iCarousel would be a good solution, but I don' know if it is possible.

What I already do is: 1-I Created a project with Storyboard that contains tab bar view. 2- One tab is used for the SKScene and saving elements (The scene is working perfectly and everything is there to switch to the second tab). 3- The second is used to present the iCarousel, where I should preview my arenas (Maps).

Can anyone help and suggest a solution to my problem? And if iCarousel is a good choice. Please tell me how to do it.

1

There are 1 answers

0
Guizmoo03 On BEST ANSWER

It's a little expensive in term of storage capacity, but it works perfectly. Here's what you'll get:

The calling view of carousel

When you click load arena, you'll get the following view to select your arena:

carousel view

You have to select the arena and the click on the green button to return back to the calling view with the chosen arena loaded.

and here's the way to achieve it:

 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
 //UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
selectedItem=[_Title objectAtIndex:indexPath.row];
[singleton setChoice:selectedItem];

tableSelectedItemIndexPath=indexPath; //Here we strore the selected item index so later when returninng to normal mode we can deselect the item

TableViewRef=tableView;

if([selectedItem isEqualToString:@"load arena])
{
    if ([[SpriteMyScene getMapsVector] count] == 0){

        UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"Absence de carte à visualiser" message:@"Il n'y a pas de carte disponible" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles: nil];
        [alert show];
    }

    else{

        [[[[self.tabBarController tabBar]items]objectAtIndex:2]setEnabled:TRUE];

        [self.tabBarController setSelectedIndex:2 ];
    }
}

if([selectedItem isEqualToString:@"save arena"])
{
    UIAlertView * alert =[[UIAlertView alloc ] initWithTitle:@"XML Save" message:@"Enter the name of the file you wish to save." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
    alert.alertViewStyle = UIAlertViewStylePlainTextInput;
    [alert addButtonWithTitle:@"OK"];
    [alert show];

    //We programmarically remove the selection
    [TableViewRef deselectRowAtIndexPath:tableSelectedItemIndexPath animated:YES];

}

if([selectedItem isEqualToString:@"delete arena"])
{
    int yCoordinate=40;
    //This is the scroll pan ein which the xml file list is displayed
    _polygonView = [[UIScrollView alloc] initWithFrame: CGRectMake ( 0, 0, 500, 300)];
    _polygonView.backgroundColor=[UIColor clearColor];
    [_polygonView setScrollEnabled:YES]; //we activated the scroll function

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); //here we all directory paths on ios
    NSString *docDir;

    docDir=[paths objectAtIndex:0]; //this is the path to Document directory


    //we get an array containing all files in a given directory. This is same as File class in java
    NSArray *directoryContent = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:docDir error:NULL];
    for (int i = 0; i < (int)[directoryContent count]; i++)
    {
        NSRange range;
        range=[[directoryContent objectAtIndex:i] rangeOfString:@".xml"];
        if(range.location != NSNotFound)
        {

            //this index is used ot exlude the .xml part when displaying teh name sof the files to the user
            int ToIndex=[[directoryContent objectAtIndex:i] length];
            ToIndex-=4;

            NSString *btnTitle=[[directoryContent objectAtIndex:i] substringToIndex:ToIndex];
            if(![btnTitle isEqualToString:@"imageData"])
            {
                UIButton *FileButton = [[UIButton alloc] initWithFrame:CGRectMake(165, yCoordinate, 200, 40)];
                [FileButton setTitle:btnTitle forState:UIControlStateNormal];
                [FileButton setTitleColor:[UIColor whiteColor]forState:UIControlStateNormal];
                [FileButton setEnabled:YES];
                [FileButton setUserInteractionEnabled:YES];
                [FileButton addTarget: self action: @selector(buttonIsPressed:) forControlEvents: UIControlEventTouchDown];
                [FileButton setBackgroundColor:[UIColor blueColor]];
                [_polygonView addSubview:FileButton];
                yCoordinate+=45;
            }
        }

    }

    _polygonView.contentSize = CGSizeMake(self.view.frame.size.width, self.view.frame.size.height *2.5);

    //This is the licensed class that is used to create a window pane
    CustomIOS7AlertView* alertView=[[CustomIOS7AlertView alloc]init];
    alertView.tag=1;
    [alertView setFrame:CGRectMake(500, 0, 500, 500)];

    [alertView setContainerView:_polygonView];
    [alertView setButtonTitles:[NSMutableArray arrayWithObjects:@"Delete File", @"Cancel", nil]];
    [alertView setDelegate:self];
    [alertView show];
}

....
/*
 * This method is used ot read the user input text value when user enters the name of the xml file
 * This is used when saving a xml file
 */

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{  if (buttonIndex == 1) {

    UITextField* fileName = [alertView textFieldAtIndex:0];

    XMLHandler* xml=[[XMLHandler alloc] init];

    [xml setXmlFileName:fileName.text];

    [[SpriteViewController getSceneRef] snapShotScene:fileName.text];

    //we save the image file
    [xml generateImageFile:[SpriteMyScene getImageData]:[SpriteMyScene getImageFileName]];

    //this function gets the _nodeDictionnary as argument
    NSMutableDictionary* tmp = [singleton getSceneNodeDictionnary];

    [xml generateXML:tmp];

}}

and the picture are taken each time the user save an arena using this method:

- (void) snapShotScene: (NSString*) imageName{

UIGraphicsBeginImageContextWithOptions(self.view.bounds.size, NO, 0.50);
[self.view drawViewHierarchyInRect:self.view.bounds afterScreenUpdates:YES];
UIImage * image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

@autoreleasepool
{

    //convert image into .png format.
    imageData = UIImagePNGRepresentation(image);

    imageFileName= imageName;

    [mapsVector addObject: imageData];
    [fileNamesVector addObject: imageFileName];

 }

}

For the iCarousel class, use this link: The iCarousel repository I hope this will help.