I am trying to load the background of the map programatically based on a float called "progress" from 0.000000 - 1.000000
For some reason when I set it to zero, the moon is in the right place y-wise, but in the center x-wise instead of being at 0.75 of the screen at 0.000000 and 0.5 of the screen at 0.499999.
The sun doesn't appear at all ever, and it's not my math being SUPER off because when i set the center to (0,0) or self.view.center, I still don't see it... the dayImageView isn't covering it either because at 0.600000 I can't see it behind.
I'm guessing it's something with the default origin of the images or something. Anyone know why the moon is off, and the sun doesn't even appear?
Your time and help are greatly appreciated.
Code:
- (void)setupCvBackgroundView {
//Display images
UIImage *nightImage = [UIImage imageNamed:@"Night BG.png"];
UIImageView *nightImageView = [[UIImageView alloc] initWithImage:nightImage];
[cvBackgroundView addSubview:nightImageView];
UIImage *dayImage = [UIImage imageNamed:@"Day BG.png"];
UIImageView *dayImageView = [[UIImageView alloc] initWithImage:dayImage];
[cvBackgroundView addSubview:dayImageView];
UIImage *moonImage = [UIImage imageNamed:@"Moon.png"];
UIImageView *moonImageView = [[UIImageView alloc] initWithImage:moonImage];
[cvBackgroundView insertSubview:moonImageView aboveSubview:dayImageView];
UIImage *sunImage = [UIImage imageNamed:@"Sun.png"];
UIImageView *sunImageView = [[UIImageView alloc] initWithImage:sunImage];
[cvBackgroundView insertSubview:sunImageView aboveSubview:moonImageView];
//SUN/MOON POSITIONS
float progress = [[NSUserDefaults standardUserDefaults] floatForKey:@"land1progress"];
if (progress > 0.500000) {
sunImageView.center = CGPointMake((self.view.frame.size.width * 0.5) + ((self.view.frame.size.width * 0.25) *((progress - 0.5) * 2)), self.view.frame.size.height - ((self.view.frame.size.height * 0.75) * ((progress - 0.5) * 2)));
moonImageView.hidden = YES;
} if (progress < 0.500000) {
moonImageView.center = CGPointMake((self.view.frame.size.width * 0.75) - (self.view.frame.size.width * ((progress * 2) * 0.25)), ((self.view.frame.size.height * 0.75) * (progress * 2)) + (self.view.frame.size.height * 0.25));
sunImageView.hidden = YES;
} else {
sunImageView.hidden = YES;
moonImageView.hidden = YES;
}
//BG TRANSPARENCIES
//display day bg over night bg
dayImageView.alpha = progress;
[nightImageView release];
[dayImageView release];
[moonImageView release];
[sunImageView release];
}