Alright, I am having alot of issues with creating my own class called StageClass. Do you know of any tutorial on how to create a custom class? Every google search turns up junk about how the iphone is world class ect. I'll keep looking though.
Edit: So I finally found some tutorials, and here's what I'm up to:
The only problem is, I can't get the image to show up at all.
Code:
//
// StageClass.h
//
#import <Foundation/Foundation.h>
@interface StageClass : NSObject
{
// Initialization of the properties
int plantState;
int water;
int harvest;
int harvestCounter;
int fertilizer;
UIImageView *imageView;
}
@property(assign, readwrite) int plantState;
@property(assign, readwrite) int water;
@property(assign, readwrite) int harvest;
@property(assign, readwrite) int harvestCounter;
@property(assign, readwrite) int fertilizer;
@property(retain, readwrite) UIImageView *imageView;
@end
Code:
// StageClass.m
#import "StageClass.h"
@implementation StageClass
@synthesize plantState = _plantState;
@synthesize water = _water;
@synthesize fertilizer = _fertilizer;
@synthesize harvest = _harvest;
@synthesize harvestCounter = _harvestCounter;
@synthesize imageView = _imageView;
- (void)endDayCycle{
switch (plantState) {
case 0:
water = 0;
fertilizer = 0;
[imageView stopAnimating];
imageView.userInteractionEnabled = YES;
imageView.frame = CGRectMake(50, 430, 320, 350);
imageView.animationImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"empty_plot_filler.png"],nil] ;
[imageView startAnimating];
plantState = 0;
break;
case 1:
if (fertilizer >= 3) {
if (water >= 3) {
water = 0;
fertilizer = 0;
[imageView stopAnimating];
imageView.animationImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"001.png"],
[UIImage imageNamed:@"001.png"],nil] ;;
[imageView startAnimating];
plantState = 2;
} else {
[imageView stopAnimating];
imageView.animationImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"empty_plot_filler.png"],nil] ;;
[imageView startAnimating];
plantState = 0;
}
} else {
[imageView stopAnimating];
imageView.animationImages = [[NSArray alloc] initWithObjects:
[UIImage imageNamed:@"empty_plot_filler.png"],nil] ;;
[imageView startAnimating];
plantState = 0;
}
break;
}
}
-(void) dealloc
{
[imageView release];
[super dealloc];
}
@end
Code:
//exerpt from ViewController.h:
IBOutlet StageClass *plant1;
}
@property(nonatomic,retain) StageClass *plant1;
Code:
//exerpt from -(void)viewdidload from ViewController.m:
plant1.imageView = [[UIImageView alloc] initWithFrame:self.view.frame];
plant1.imageView.userInteractionEnabled = YES;
plant1.imageView.frame = CGRectMake(50, 0, 320, 350);
plant1.imageView.animationImages = empty_plot;
plant1.imageView.animationDuration = 0.5;
plant1.imageView.animationRepeatCount = 0;
[plant1.imageView startAnimating];