Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Game Development

Reply
 
LinkBack Thread Tools Display Modes
Old 07-20-2011, 10:06 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 50
schenker is on a distinguished road
Default making a common class

Hi, i need to often include the below codes for animation purpose throughout my program. For efficiency purpose, i would like to make this as a class that i can often refer to.

Code:
            UIImageView *gameOver;
            gameOver=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 320, 477)];
            gameOver.image=[UIImage imageNamed:@"gameover.png"];
            gameOver.alpha=0.0;
            [self.view addSubview:gameOver];
            [UIView beginAnimations:nil context:gameOver];
            [UIView setAnimationDuration:2.0];
            gameOver.alpha=1.0;
            [UIView commitAnimations];
            [gameOver release];
How can i make this as a common class?

i tried creating a Transition class, but not sure if it is right. The codes are as follows:

Code:
+(void)beginTransition:(UIImageView *)theImageView:(struct CGRectMake *)dimension:(NSString *)imageFile:(float)startAlpha:(float)endAlpha;
Hope to get some help. Thanks.
schenker is offline   Reply With Quote
Old 07-20-2011, 08:50 PM   #2 (permalink)
almostfunnydev
iPhone Dev SDK Supporter
 
rocotilos's Avatar
 
Join Date: Oct 2009
Age: 34
Posts: 3,015
rocotilos is on a distinguished road
Default

For me I just do it like this:

Code:
-(void)beginTransition:(UIImageView *)theImageView:(CGRect *)dimension:(NSString *)imageFile:(CGFloat)startAlpha:(CGFloat)endAlpha;
rocotilos is offline   Reply With Quote
Old 07-20-2011, 10:26 PM   #3 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 50
schenker is on a distinguished road
Default

Quote:
Originally Posted by rocotilos View Post
For me I just do it like this:

Code:
-(void)beginTransition:(UIImageView *)theImageView:(CGRect *)dimension:(NSString *)imageFile:(CGFloat)startAlpha:(CGFloat)endAlpha;
Hi, Thanks. But how do you pass the coordinates and dimensions to CGRect in the implementation. I've searched everywhere but cant find anything to help me.
schenker is offline   Reply With Quote
Old 07-20-2011, 10:50 PM   #4 (permalink)
Registered Member
 
Join Date: Jun 2011
Location: Sydney, Australia
Posts: 44
new2objectivec is on a distinguished road
Default

CGRectMake would return a CGRect

e.g.:
CGRect rect1 = CGRectMake(100, 100, 100, 100);
CGRect rect2 = CGRectMake(190, 190, 100, 100);

Have a look at http://iphonedevelopertips.com/c/cgr...functions.html
new2objectivec is offline   Reply With Quote
Old 07-21-2011, 02:45 AM   #5 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 50
schenker is on a distinguished road
Default

Quote:
Originally Posted by new2objectivec View Post
CGRectMake would return a CGRect

e.g.:
CGRect rect1 = CGRectMake(100, 100, 100, 100);
CGRect rect2 = CGRectMake(190, 190, 100, 100);

Have a look at CGRect, CGSize and CGPoint Functions

i did the following in my, .h file:

Code:
#import <UIKit/UIKit.h>

struct Rectangle {
    float point_x;
    float point_y;
    float width;
    float height;
};



@interface Transition : UIViewController {
    
    struct Rectangle *rectangle;     
 
}

@property struct Rectangle *rectangle;


-(void)beginTransition:(UIImageView *)theImageView:(CGRect)dimension:(NSString *)imageFile:(float)startAlpha:(float)endAlpha;

@end
in my .m file i did this:


Code:
#import "Transition.h"


@implementation Transition


@synthesize rectangle;

-(void)beginTransition:(UIImageView *)theImageView:(CGRect )dimension:(NSString *)imageFile:(float)startAlpha:(float)endAlpha
{
    UIImageView *myImageView=theImageView;
    
    CGRect myrect=CGRectMake(rectangle->point_x, rectangle->point_y, rectangle->width, rectangle->height);
    myrect=dimension;
    
    
    myImageView=[[UIImageView alloc]initWithFrame:dimension];
    myImageView.image=[UIImage imageNamed:imageFile];
    myImageView.alpha=startAlpha;
    [self.view addSubview:myImageView];
    [UIView beginAnimations:nil context:myImageView];
    [UIView setAnimationDuration:2.0];
    myImageView.alpha=endAlpha;
    [UIView commitAnimations];
    [myImageView release];

}


@end

I know something is terribly wrong in my .m file, esp the way im using the structure. Sure enough program crashes when executing that portion. Where am i going wrong? Thanks.
schenker is offline   Reply With Quote
Old 07-22-2011, 01:43 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 50
schenker is on a distinguished road
Default

Great! i fixed it myself. Thanks for all your response.
schenker is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 412
10 members and 402 guests
AppleDev, chemistry, Emy, hussain1982, ipodphone, mistergreen2011, pipposanta, Retouchable, skrew88, SLIC
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,679
Threads: 94,128
Posts: 402,923
Top Poster: BrianSlick (7,990)
Welcome to our newest member, xzoonxoom
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 08:19 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0