Ce anime le UIImageView dans le impactdrawarray:Insertion d'un NSString dans pathForResource de NSBundle?
if (((impact *) [impactarray objectAtIndex:iv]).animframe == 70){
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image =
[UIImage imageWithContentsOfFile:
[[NSBundle mainBundle] pathForResource:@"explosionA71"
ofType:@"png"]];
}
if (((impact *) [impactarray objectAtIndex:iv]).animframe == 71){
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image =
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@"explosionA72"
ofType:@"png"]];
}
Rien n'apparaît avec ceci:
NSString *myString2 =
[NSString stringWithFormat:@"A%d",
((impact *) [impactarray objectAtIndex:iv]).animframe;
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image =
[UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:(@"explosion%d", myString2)
ofType:@"png"]];
Ma référence pour l'utilisation NSString (exemple)
NSString *myString23 = [NSString stringWithFormat:@"$%d", money];
moneylabel.text = myString23;
Comment puis-je utiliser une variable dans le nom de fichier? Existe-t-il un moyen de charger une image dans un dossier de ressources par index? quelque chose comme imageByIndex:currentanimationframe
? Je n'ai rien vu dans la documentation d'UIImage.
Réponse aux commentaires:
NSString *myString2 = [NSString stringWithFormat:@"A%d", ((impact *) [impactarray objectAtIndex:iv]).animframe];
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image = [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"explosion%d", myString2] ofType:@"png"]];
et
NSString *imagename = [NSString stringWithFormat:@"A%d", ((impact *) [impactarray objectAtIndex:iv]).animframe];
UIImage *myImage = [UIImage imageNamed:imagename];
((UIImageView *) [impactdrawarray objectAtIndex:iv]).image = myImage;
deux compiler et exécuter, mais l'image ne montre pas.
Qu'avez-vous essayé? Dire "ça ne marche pas" n'est pas particulièrement utile sans quelques explications supplémentaires. –
Les deux blocs de code ci-dessous "Réponse aux commentaires" est ce que j'ai essayé. Les deux compilent et courent mais aucune image n'apparaît. – user128526