Animaci sprite přes MKMapView

hlasů
2

Aniž by se dostal do OpenGL (Quartz 2D je v pořádku):

  1. Řekněme, že mám obraz, který chci se pohybovat po celé mapě nějakým způsobem tekutiny. Například obraz roviny „létání“ po celé mapě. Byl jsem schopen to udělat pomocí MKAnnotation, je NSTimer a pohrával si s mírou lat / lon změny a rychlosti s časovačem. Nicméně předpokládám, že to není ideální, i když výsledky vypadají docela slušné. Dokážete si představit lepší způsob?

  2. Nyní řekněme, že chci tento obraz má být animované (myslím: animovaný GIF). Nemohu dělat obvyklé UIImageViewsérií animationFrames, protože všechno, co mají přístup k oblasti MKAnnotationView je UIImage. Jak by vás řešení tohoto problému?

Uvědomuji si, že # 2 by mohly být řešeny s UIImageView na horní části mapy obsahující animationImages. Nicméně, pak budu muset ručně zpracovat překládat pohyb letadla nebo rakety, nebo cokoliv, protože oblast MapView změnil v závislosti na pohybu uživatele v reálném světě, nebo uživatel zoomování (rolování není dovoleno v mém app).

Co myslíš?

Položena 20/08/2009 v 04:06
zdroj uživatelem
V jiných jazycích...                            


1 odpovědí

hlasů
5

Myslím, že jsem přišel na řešení # 2. podtřídy I MKAnnotationView a napsal nějaký kód pro přidání UIImageView (s animací snímků) jako subview.

//AnimatedAnnotation.h

#import <Foundation/Foundation.h>
#import <MapKit/MapKit.h>

@interface AnimatedAnnotation : MKAnnotationView
{
    UIImageView* _imageView;
    NSString *imageName;
    NSString *imageExtension;
    int imageCount;
    float animationDuration;
}

@property (nonatomic, retain) UIImageView* imageView;
@property (nonatomic, retain) NSString* imageName;
@property (nonatomic, retain) NSString* imageExtension;
@property (nonatomic) int imageCount;
@property (nonatomic) float animationDuration;


- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier imageName:(NSString *)name imageExtension:(NSString *)extension imageCount:(int)count animationDuration:(float)duration
;

@end

//AnimatedAnnotation.m

#import "AnimatedAnnotation.h"

@implementation AnimatedAnnotation
@synthesize imageView = _imageView;
@synthesize imageName, imageCount, imageExtension,animationDuration;

- (id)initWithAnnotation:(id <MKAnnotation>)annotation reuseIdentifier:(NSString *)reuseIdentifier imageName:(NSString *)name imageExtension:(NSString *)extension imageCount:(int)count animationDuration:(float)duration
{
    self = [super initWithAnnotation:annotation reuseIdentifier:reuseIdentifier];
    self.imageCount = count;
    self.imageName = name;
    self.imageExtension = extension;
    self.animationDuration = duration;
    UIImage *image = [UIImage imageNamed:[NSString stringWithFormat:@"%@0.%@",name,extension]];
    self.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    self.backgroundColor = [UIColor clearColor];


    _imageView = [[UIImageView alloc] initWithFrame:self.frame];
    NSMutableArray *images = [[NSMutableArray alloc] init];
    for(int i = 0; i < count; i++ ){
        [images addObject:[UIImage imageNamed:[NSString stringWithFormat:@"%@%d.%@", name, i, extension]]];
    }


    _imageView.animationDuration = duration;
    _imageView.animationImages = images;
    _imageView.animationRepeatCount = 0;
    [_imageView startAnimating];

    [self addSubview:_imageView];

    return self;
}

-(void) dealloc
{
    [_imageView release];
    [super dealloc];
}


@end
Odpovězeno 20/08/2009 v 05:42
zdroj uživatelem

Cookies help us deliver our services. By using our services, you agree to our use of cookies. Learn more