pasar información de la colección Ver al juego Escena
He creado un juego usando SpriteKit (GameScene y GameViewController) y Objective-C. Todo allí funciona bien. Dentro de la misma aplicación, he creado un UIViewController y un segundo viewController en storyboard que usa CollectionView. Tengo el collectionView cargando la matriz.
Quiero poder tocar en una colección collectionView Cell y hacer que abra el gameView. Lo que puedo hacer. Sin embargo, me gustaría pasar información de la colección ViewView a GameScene para poder cargar la imagen de fondo y otra información para individualizar GameScene para cada collectionViewCell.
Aquí está mi código para la colección.
#import "collectionViewController.h"
#import "GameScene.h"
#import "GameViewController.h"
@implementation collectionViewController
@synthesize animalArray,theImage,StringPicture,myCell;
-(void) viewDidLoad {
[super viewDidLoad];
animalArray = [NSArray arrayWithObjects:@"Cat.png",
@"image1.png",
@"image2.png",
@"image3.png",
,nil];
}
-(NSInteger) numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
return 1;
}
-(NSInteger) collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
return animalArray.count;
}
-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
myCell = [collectionView dequeueReusableCellWithReuseIdentifier:@"cell" forIndexPath:indexPath];
UIImage *images;
long row = [indexPath row];
images = [UIImage imageNamed:animalArray[row]];
myCell.image1.image = images;
return myCell;
}
-(void) collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"indexPath.row:%ld",(long)indexPath.row);
if (indexPath.row==1) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"GameSceneOne"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
NSLog(@"mycell.image1.image:%@",myCell.image1.image);
[self presentViewController:vc animated:YES completion:NULL];
}
if (indexPath.row==2) {
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [sb instantiateViewControllerWithIdentifier:@"GameSceneOne"];
vc.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentViewController:vc animated:YES completion:NULL];
}
}
Intenté asignar GameScene.image a vc.image pero uno es GameView y el otro es UIViewController, así que no puedo hacer eso.
He intentado usar un segue pero aún así la información no se puede pasar de una a otra.
¿Cómo debería hacer esto?