SlideShare una empresa de Scribd logo
1 de 88
Descargar para leer sin conexión
Making Things Move
           on the iPhone
                             Keith Peters
                           www.bit-101.com




Wednesday, March 4, 2009
www.bit-101.com/
                               360iDev/
                            presentation.zip


Wednesday, March 4, 2009
CoreAnimation



Wednesday, March 4, 2009
Background



Wednesday, March 4, 2009
Background
                           2005




Wednesday, March 4, 2009
Background
                           2005
                                     2007



Wednesday, March 4, 2009
Background
                           2005
                                     2007
                                               2008

Wednesday, March 4, 2009
Wednesday, March 4, 2009
Wednesday, March 4, 2009
Wednesday, March 4, 2009
What is Animation?



Wednesday, March 4, 2009
Wednesday, March 4, 2009
Wednesday, March 4, 2009
Coded Animation




Wednesday, March 4, 2009
Coded Animation
                                Apply a
                                 rule




Wednesday, March 4, 2009
Coded Animation
                                Apply a
                                 rule




                                           Change
                                          something


Wednesday, March 4, 2009
Coded Animation
                                Apply a
                                 rule




                    Update                 Change
                  the screen              something


Wednesday, March 4, 2009
Coded Animation
                                Apply a
                                 rule




                    Update                 Change
                  the screen              something


Wednesday, March 4, 2009
Make something
                          to move


Wednesday, March 4, 2009
Make something
                          to move


Wednesday, March 4, 2009
Make something
                          to move

                           (project files: Animation101)


Wednesday, March 4, 2009
// interface
  UIImageView *ball;




  // viewDidLoad
  ball = [[UIImageView alloc] initWithImage:
            [UIImage imageNamed:@quot;ball.pngquot;]];
  [self.view addSubview:ball];




Wednesday, March 4, 2009
NSTimer




Wednesday, March 4, 2009
NSTimer
  [NSTimer
     scheduledTimerWithTimeInterval:1.0/60.0
     target:self
     selector:@selector(onTimer)
     userInfo:nil
     repeats:YES];




Wednesday, March 4, 2009
Moving UIViews




Wednesday, March 4, 2009
Moving UIViews

                   • view.center




Wednesday, March 4, 2009
Moving UIViews

                   • view.center
                   • view.transform



Wednesday, March 4, 2009
Moving UIViews

                   • view.center
                   • view.transform
                   • view.frame


Wednesday, March 4, 2009
// interface
     float x;
     float y;



                           // viewDidLoad
                           x = 50.0;
                           y = 50.0;




Wednesday, March 4, 2009
ball.center = CGPointMake(x, y);
  x += 2.0;
  y += 3.0;




Wednesday, March 4, 2009
ball.frame = CGRectMake(x, y, width, height);
  x += 2.0;
  y += 3.0;




Wednesday, March 4, 2009
ball.transform =
      CGAffineTransformMakeTranslation(x, y);
  x += 2.0;
  y += 3.0;




Wednesday, March 4, 2009
ball.transform =
      CGAffineTransformTranslate(
          ball.transform, 2.0, 3.0);




Wednesday, March 4, 2009
Which is fastest?




Wednesday, March 4, 2009
Which is fastest?

                   • view.center




Wednesday, March 4, 2009
Which is fastest?

                   • view.center
                   • view.transform (~2-3x)



Wednesday, March 4, 2009
Which is fastest?

                   • view.center
                   • view.transform (~2-3x)
                   • view.frame (~2-3x)


Wednesday, March 4, 2009
Velocity




                           (project files:Velocity)

Wednesday, March 4, 2009
Velocity


                               +
                           (project files:Velocity)

Wednesday, March 4, 2009
speed
                              and
                           direction




Wednesday, March 4, 2009
speed
                              and
                           direction
                                            y velocity




                               x velocity


Wednesday, March 4, 2009
- y velocity



                           - x velocity          + x velocity




                                          + y velocity


Wednesday, March 4, 2009
Wednesday, March 4, 2009
// interface:
  float vx;
  float vy;




Wednesday, March 4, 2009
// interface:
  float vx;
  float vy;


                    // viewDidLoad:
                    vx = 2.0;
                    vy = 3.0;




Wednesday, March 4, 2009
// interface:
  float vx;
  float vy;


                    // viewDidLoad:
                    vx = 2.0;
                    vy = 3.0;

                           // onTimer:
                           ball.center = CGPointMake(x, y);
                           x += vx;
                           y += vy;


Wednesday, March 4, 2009
speed




                             angle


                           (project files: AngularVelocity)

Wednesday, March 4, 2009
y velocity
                                     speed                    =
                                                          sin(angle)
                                                               x
                                                            speed
                                 angle
                           x velocity = cos(angle) x speed
                              (project files: AngularVelocity)

Wednesday, March 4, 2009
Wednesday, March 4, 2009
// interface:
  float angle;
  float speed;




Wednesday, March 4, 2009
// interface:            // viewDidLoad:
  float angle;             angle = 45.0;
  float speed;             speed = 4.0;




Wednesday, March 4, 2009
// interface:            // viewDidLoad:
  float angle;             angle = 45.0;
  float speed;             speed = 4.0;




  // onTimer:
  ball.center = CGPointMake(x, y);
  x += cos(angle * M_PI / 180.0) * speed;
  y += sin(angle * M_PI / 180.0) * speed;




Wednesday, March 4, 2009
Acceleration




                           (project files: Acceleration)

Wednesday, March 4, 2009
Acceleration


                                 +
                           (project files: Acceleration)

Wednesday, March 4, 2009
Wednesday, March 4, 2009
// interface:
  float ax;
  float ay;




Wednesday, March 4, 2009
// interface:            // viewDidLoad:
  float ax;                ax = 0.07;
  float ay;                ay = 0.1;




Wednesday, March 4, 2009
// interface:                             // viewDidLoad:
  float ax;                                 ax = 0.07;
  float ay;                                 ay = 0.1;



                           // onTimer:
                           ball.center = CGPointMake(x, y);
                           x += vx;
                           y += vy;
                           vx += ax;
                           vy += ay;


Wednesday, March 4, 2009
Bouncing




                           (project files: Bouncing)

Wednesday, March 4, 2009
Wednesday, March 4, 2009
-x velocity y velocity




                                         y velocity
                            x velocity


Wednesday, March 4, 2009
Wednesday, March 4, 2009
// interface:
              float bounce;




Wednesday, March 4, 2009
// interface:
              float bounce;




                              // viewDidLoad:
                              bounce = -1.0;




Wednesday, March 4, 2009
ball.center = CGPointMake(x, y);
  x += vx;
  y += vy;
  if(x > 300)	 	 	  // 320 - radius (20)
  {
  	 x = 300;
  	 vx *= bounce;
  }
  else if(x < 20)		 // 0 + radius
  {
  	 x = 20;
  	 vx *= bounce;
  }


Wednesday, March 4, 2009
if(y > 440)	 	 // 460 - radius
              	
  {
  	 y = 440;
  	 vy *= bounce;
  }
  else if(y < 20)	 	 // 0 + radius
  {
  	 y = 20;
  	 vy *= bounce;
  }



Wednesday, March 4, 2009
Gravity



                               acceleration
                                   (+y)



Wednesday, March 4, 2009
Wednesday, March 4, 2009
// interface:
     float gravity;




Wednesday, March 4, 2009
// interface:
     float gravity;



                           // viewDidLoad:
                           gravity = 0.5;




Wednesday, March 4, 2009
// interface:
     float gravity;



                           // viewDidLoad:
                           gravity = 0.5;



                                             // onTimer:
                                             vy += gravity;



Wednesday, March 4, 2009
Wednesday, March 4, 2009
acceleration.y



                           acceleration.x



Wednesday, March 4, 2009
@interface GravityViewController :
  UIViewController <UIAccelerometerDelegate>
  {
  	 UIImageView *ball;
  	 float x;
  	 float y;
  	 float vx;
  	 float vy;
  	 float bounce;
  	 CGPoint gravity;
  }



Wednesday, March 4, 2009
Wednesday, March 4, 2009
// viewDidLoad
  gravity = CGPointZero;
  [[UIAccelerometer sharedAccelerometer]
      setDelegate:self];




Wednesday, March 4, 2009
// viewDidLoad
  gravity = CGPointZero;
  [[UIAccelerometer sharedAccelerometer]
      setDelegate:self];

  - (void)accelerometer:(UIAccelerometer *)accelerometer
          didAccelerate:(UIAcceleration *)acceleration
  {
  	 gravity = CGPointMake(acceleration.x,
                         -acceleration.y);
  }




Wednesday, March 4, 2009
// viewDidLoad
  gravity = CGPointZero;
  [[UIAccelerometer sharedAccelerometer]
      setDelegate:self];

  - (void)accelerometer:(UIAccelerometer *)accelerometer
          didAccelerate:(UIAcceleration *)acceleration
  {
  	 gravity = CGPointMake(acceleration.x,
                         -acceleration.y);
  }

  // onTimer
  vx += gravity.x;
  vy += gravity.y;


Wednesday, March 4, 2009
Do we still have time?



Wednesday, March 4, 2009
Dragging and Throwing



Wednesday, March 4, 2009
Wednesday, March 4, 2009
// interface
    BOOL dragging;




Wednesday, March 4, 2009
// interface           // viewDidLoad
    BOOL dragging;         dragging = NO;




Wednesday, March 4, 2009
// interface                         // viewDidLoad
    BOOL dragging;                       dragging = NO;



                           - (void)onTimer
                           {
                              if(!dragging)
                              {
                                 ...
                              }
                           }


Wednesday, March 4, 2009
- (void)touchesBegan:(NSSet *)touches
          withEvent:(UIEvent *)event
  {
  	 UITouch *touch = [touches anyObject];
  	 CGPoint point = [touch locationInView:self.view];
  	 float dx = point.x - x;
  	 float dy = point.y - y;
  	 float dist = sqrt(dx * dx + dy * dy);
  	 if(dist < 20)
  	{
  		    dragging = YES;
  		    x = point.x;
  		    y = point.y;
  		    vx = 0;
  		    vy = 0;
  	}
  }



Wednesday, March 4, 2009
- (void)touchesEnded:(NSSet *)touches
          withEvent:(UIEvent *)event
  {
  	 dragging = NO;
  }




Wednesday, March 4, 2009
- (void)touchesMoved:(NSSet *)touches
          withEvent:(UIEvent *)event
  {
  	 if(dragging)
  	{
  		    UITouch *touch = [touches anyObject];
  		    CGPoint point = [touch locationInView:self.view];
  		    vx = point.x - x;
  		    vy = point.y - y;
  		    x = point.x;
  		    y = point.y;
  		    ball.center = point;
  	}
  }	




Wednesday, March 4, 2009
Thank you
                   • Keith Peters
                   • kp@bit-101.com
                   • www.bit-101.com
                   • www.wickedpissahgames.com
                   • www.bit-101.com/360iDev/presentation.zip

Wednesday, March 4, 2009

Más contenido relacionado

Más de John Wilker

Introtoduction to cocos2d
Introtoduction to  cocos2dIntrotoduction to  cocos2d
Introtoduction to cocos2dJohn Wilker
 
Getting Started with OpenGL ES
Getting Started with OpenGL ESGetting Started with OpenGL ES
Getting Started with OpenGL ESJohn Wilker
 
User Input in a multi-touch, accelerometer, location aware world.
User Input in a multi-touch, accelerometer, location aware world.User Input in a multi-touch, accelerometer, location aware world.
User Input in a multi-touch, accelerometer, location aware world.John Wilker
 
Physics Solutions for Innovative Game Design
Physics Solutions for Innovative Game DesignPhysics Solutions for Innovative Game Design
Physics Solutions for Innovative Game DesignJohn Wilker
 
Getting Oriented with MapKit: Everything you need to get started with the new...
Getting Oriented with MapKit: Everything you need to get started with the new...Getting Oriented with MapKit: Everything you need to get started with the new...
Getting Oriented with MapKit: Everything you need to get started with the new...John Wilker
 
Getting Started with iPhone Game Development
Getting Started with iPhone Game DevelopmentGetting Started with iPhone Game Development
Getting Started with iPhone Game DevelopmentJohn Wilker
 
Internationalizing Your Apps
Internationalizing Your AppsInternationalizing Your Apps
Internationalizing Your AppsJohn Wilker
 
Optimizing Data Caching for iPhone Application Responsiveness
Optimizing Data Caching for iPhone Application ResponsivenessOptimizing Data Caching for iPhone Application Responsiveness
Optimizing Data Caching for iPhone Application ResponsivenessJohn Wilker
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On RailsJohn Wilker
 
Integrating Push Notifications in your iPhone application with iLime
Integrating Push Notifications in your iPhone application with iLimeIntegrating Push Notifications in your iPhone application with iLime
Integrating Push Notifications in your iPhone application with iLimeJohn Wilker
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core AnimationJohn Wilker
 
P2P Multiplayer Gaming
P2P Multiplayer GamingP2P Multiplayer Gaming
P2P Multiplayer GamingJohn Wilker
 
Using Concurrency To Improve Responsiveness
Using Concurrency To Improve ResponsivenessUsing Concurrency To Improve Responsiveness
Using Concurrency To Improve ResponsivenessJohn Wilker
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder BehindJohn Wilker
 
Mobile WebKit Development and jQTouch
Mobile WebKit Development and jQTouchMobile WebKit Development and jQTouch
Mobile WebKit Development and jQTouchJohn Wilker
 
Accelerometer and OpenGL
Accelerometer and OpenGLAccelerometer and OpenGL
Accelerometer and OpenGLJohn Wilker
 
Deep Geek Diving into the iPhone OS and Framework
Deep Geek Diving into the iPhone OS and FrameworkDeep Geek Diving into the iPhone OS and Framework
Deep Geek Diving into the iPhone OS and FrameworkJohn Wilker
 
NSNotificationCenter vs. AppDelegate
NSNotificationCenter vs. AppDelegateNSNotificationCenter vs. AppDelegate
NSNotificationCenter vs. AppDelegateJohn Wilker
 
From Flash to iPhone
From Flash to iPhoneFrom Flash to iPhone
From Flash to iPhoneJohn Wilker
 

Más de John Wilker (20)

Introtoduction to cocos2d
Introtoduction to  cocos2dIntrotoduction to  cocos2d
Introtoduction to cocos2d
 
Getting Started with OpenGL ES
Getting Started with OpenGL ESGetting Started with OpenGL ES
Getting Started with OpenGL ES
 
User Input in a multi-touch, accelerometer, location aware world.
User Input in a multi-touch, accelerometer, location aware world.User Input in a multi-touch, accelerometer, location aware world.
User Input in a multi-touch, accelerometer, location aware world.
 
Physics Solutions for Innovative Game Design
Physics Solutions for Innovative Game DesignPhysics Solutions for Innovative Game Design
Physics Solutions for Innovative Game Design
 
Getting Oriented with MapKit: Everything you need to get started with the new...
Getting Oriented with MapKit: Everything you need to get started with the new...Getting Oriented with MapKit: Everything you need to get started with the new...
Getting Oriented with MapKit: Everything you need to get started with the new...
 
Getting Started with iPhone Game Development
Getting Started with iPhone Game DevelopmentGetting Started with iPhone Game Development
Getting Started with iPhone Game Development
 
Internationalizing Your Apps
Internationalizing Your AppsInternationalizing Your Apps
Internationalizing Your Apps
 
Optimizing Data Caching for iPhone Application Responsiveness
Optimizing Data Caching for iPhone Application ResponsivenessOptimizing Data Caching for iPhone Application Responsiveness
Optimizing Data Caching for iPhone Application Responsiveness
 
I Phone On Rails
I Phone On RailsI Phone On Rails
I Phone On Rails
 
Integrating Push Notifications in your iPhone application with iLime
Integrating Push Notifications in your iPhone application with iLimeIntegrating Push Notifications in your iPhone application with iLime
Integrating Push Notifications in your iPhone application with iLime
 
Starting Core Animation
Starting Core AnimationStarting Core Animation
Starting Core Animation
 
P2P Multiplayer Gaming
P2P Multiplayer GamingP2P Multiplayer Gaming
P2P Multiplayer Gaming
 
Using Concurrency To Improve Responsiveness
Using Concurrency To Improve ResponsivenessUsing Concurrency To Improve Responsiveness
Using Concurrency To Improve Responsiveness
 
Leaving Interface Builder Behind
Leaving Interface Builder BehindLeaving Interface Builder Behind
Leaving Interface Builder Behind
 
Mobile WebKit Development and jQTouch
Mobile WebKit Development and jQTouchMobile WebKit Development and jQTouch
Mobile WebKit Development and jQTouch
 
Accelerometer and OpenGL
Accelerometer and OpenGLAccelerometer and OpenGL
Accelerometer and OpenGL
 
Deep Geek Diving into the iPhone OS and Framework
Deep Geek Diving into the iPhone OS and FrameworkDeep Geek Diving into the iPhone OS and Framework
Deep Geek Diving into the iPhone OS and Framework
 
NSNotificationCenter vs. AppDelegate
NSNotificationCenter vs. AppDelegateNSNotificationCenter vs. AppDelegate
NSNotificationCenter vs. AppDelegate
 
Using SQLite
Using SQLiteUsing SQLite
Using SQLite
 
From Flash to iPhone
From Flash to iPhoneFrom Flash to iPhone
From Flash to iPhone
 

Último

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Drew Madelung
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 

Último (20)

Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 

Making things Move on the iPhone

  • 1. Making Things Move on the iPhone Keith Peters www.bit-101.com Wednesday, March 4, 2009
  • 2. www.bit-101.com/ 360iDev/ presentation.zip Wednesday, March 4, 2009
  • 5. Background 2005 Wednesday, March 4, 2009
  • 6. Background 2005 2007 Wednesday, March 4, 2009
  • 7. Background 2005 2007 2008 Wednesday, March 4, 2009
  • 15. Coded Animation Apply a rule Wednesday, March 4, 2009
  • 16. Coded Animation Apply a rule Change something Wednesday, March 4, 2009
  • 17. Coded Animation Apply a rule Update Change the screen something Wednesday, March 4, 2009
  • 18. Coded Animation Apply a rule Update Change the screen something Wednesday, March 4, 2009
  • 19. Make something to move Wednesday, March 4, 2009
  • 20. Make something to move Wednesday, March 4, 2009
  • 21. Make something to move (project files: Animation101) Wednesday, March 4, 2009
  • 22. // interface UIImageView *ball; // viewDidLoad ball = [[UIImageView alloc] initWithImage: [UIImage imageNamed:@quot;ball.pngquot;]]; [self.view addSubview:ball]; Wednesday, March 4, 2009
  • 24. NSTimer [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(onTimer) userInfo:nil repeats:YES]; Wednesday, March 4, 2009
  • 26. Moving UIViews • view.center Wednesday, March 4, 2009
  • 27. Moving UIViews • view.center • view.transform Wednesday, March 4, 2009
  • 28. Moving UIViews • view.center • view.transform • view.frame Wednesday, March 4, 2009
  • 29. // interface float x; float y; // viewDidLoad x = 50.0; y = 50.0; Wednesday, March 4, 2009
  • 30. ball.center = CGPointMake(x, y); x += 2.0; y += 3.0; Wednesday, March 4, 2009
  • 31. ball.frame = CGRectMake(x, y, width, height); x += 2.0; y += 3.0; Wednesday, March 4, 2009
  • 32. ball.transform = CGAffineTransformMakeTranslation(x, y); x += 2.0; y += 3.0; Wednesday, March 4, 2009
  • 33. ball.transform = CGAffineTransformTranslate( ball.transform, 2.0, 3.0); Wednesday, March 4, 2009
  • 35. Which is fastest? • view.center Wednesday, March 4, 2009
  • 36. Which is fastest? • view.center • view.transform (~2-3x) Wednesday, March 4, 2009
  • 37. Which is fastest? • view.center • view.transform (~2-3x) • view.frame (~2-3x) Wednesday, March 4, 2009
  • 38. Velocity (project files:Velocity) Wednesday, March 4, 2009
  • 39. Velocity + (project files:Velocity) Wednesday, March 4, 2009
  • 40. speed and direction Wednesday, March 4, 2009
  • 41. speed and direction y velocity x velocity Wednesday, March 4, 2009
  • 42. - y velocity - x velocity + x velocity + y velocity Wednesday, March 4, 2009
  • 44. // interface: float vx; float vy; Wednesday, March 4, 2009
  • 45. // interface: float vx; float vy; // viewDidLoad: vx = 2.0; vy = 3.0; Wednesday, March 4, 2009
  • 46. // interface: float vx; float vy; // viewDidLoad: vx = 2.0; vy = 3.0; // onTimer: ball.center = CGPointMake(x, y); x += vx; y += vy; Wednesday, March 4, 2009
  • 47. speed angle (project files: AngularVelocity) Wednesday, March 4, 2009
  • 48. y velocity speed = sin(angle) x speed angle x velocity = cos(angle) x speed (project files: AngularVelocity) Wednesday, March 4, 2009
  • 50. // interface: float angle; float speed; Wednesday, March 4, 2009
  • 51. // interface: // viewDidLoad: float angle; angle = 45.0; float speed; speed = 4.0; Wednesday, March 4, 2009
  • 52. // interface: // viewDidLoad: float angle; angle = 45.0; float speed; speed = 4.0; // onTimer: ball.center = CGPointMake(x, y); x += cos(angle * M_PI / 180.0) * speed; y += sin(angle * M_PI / 180.0) * speed; Wednesday, March 4, 2009
  • 53. Acceleration (project files: Acceleration) Wednesday, March 4, 2009
  • 54. Acceleration + (project files: Acceleration) Wednesday, March 4, 2009
  • 56. // interface: float ax; float ay; Wednesday, March 4, 2009
  • 57. // interface: // viewDidLoad: float ax; ax = 0.07; float ay; ay = 0.1; Wednesday, March 4, 2009
  • 58. // interface: // viewDidLoad: float ax; ax = 0.07; float ay; ay = 0.1; // onTimer: ball.center = CGPointMake(x, y); x += vx; y += vy; vx += ax; vy += ay; Wednesday, March 4, 2009
  • 59. Bouncing (project files: Bouncing) Wednesday, March 4, 2009
  • 61. -x velocity y velocity y velocity x velocity Wednesday, March 4, 2009
  • 63. // interface: float bounce; Wednesday, March 4, 2009
  • 64. // interface: float bounce; // viewDidLoad: bounce = -1.0; Wednesday, March 4, 2009
  • 65. ball.center = CGPointMake(x, y); x += vx; y += vy; if(x > 300) // 320 - radius (20) { x = 300; vx *= bounce; } else if(x < 20) // 0 + radius { x = 20; vx *= bounce; } Wednesday, March 4, 2009
  • 66. if(y > 440) // 460 - radius { y = 440; vy *= bounce; } else if(y < 20) // 0 + radius { y = 20; vy *= bounce; } Wednesday, March 4, 2009
  • 67. Gravity acceleration (+y) Wednesday, March 4, 2009
  • 69. // interface: float gravity; Wednesday, March 4, 2009
  • 70. // interface: float gravity; // viewDidLoad: gravity = 0.5; Wednesday, March 4, 2009
  • 71. // interface: float gravity; // viewDidLoad: gravity = 0.5; // onTimer: vy += gravity; Wednesday, March 4, 2009
  • 73. acceleration.y acceleration.x Wednesday, March 4, 2009
  • 74. @interface GravityViewController : UIViewController <UIAccelerometerDelegate> { UIImageView *ball; float x; float y; float vx; float vy; float bounce; CGPoint gravity; } Wednesday, March 4, 2009
  • 76. // viewDidLoad gravity = CGPointZero; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; Wednesday, March 4, 2009
  • 77. // viewDidLoad gravity = CGPointZero; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { gravity = CGPointMake(acceleration.x, -acceleration.y); } Wednesday, March 4, 2009
  • 78. // viewDidLoad gravity = CGPointZero; [[UIAccelerometer sharedAccelerometer] setDelegate:self]; - (void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration { gravity = CGPointMake(acceleration.x, -acceleration.y); } // onTimer vx += gravity.x; vy += gravity.y; Wednesday, March 4, 2009
  • 79. Do we still have time? Wednesday, March 4, 2009
  • 82. // interface BOOL dragging; Wednesday, March 4, 2009
  • 83. // interface // viewDidLoad BOOL dragging; dragging = NO; Wednesday, March 4, 2009
  • 84. // interface // viewDidLoad BOOL dragging; dragging = NO; - (void)onTimer { if(!dragging) { ... } } Wednesday, March 4, 2009
  • 85. - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self.view]; float dx = point.x - x; float dy = point.y - y; float dist = sqrt(dx * dx + dy * dy); if(dist < 20) { dragging = YES; x = point.x; y = point.y; vx = 0; vy = 0; } } Wednesday, March 4, 2009
  • 86. - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { dragging = NO; } Wednesday, March 4, 2009
  • 87. - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { if(dragging) { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self.view]; vx = point.x - x; vy = point.y - y; x = point.x; y = point.y; ball.center = point; } } Wednesday, March 4, 2009
  • 88. Thank you • Keith Peters • kp@bit-101.com • www.bit-101.com • www.wickedpissahgames.com • www.bit-101.com/360iDev/presentation.zip Wednesday, March 4, 2009