SlideShare ist ein Scribd-Unternehmen logo
1 von 19
Downloaden Sie, um offline zu lesen
Openframeworks
         x iPad Game Design (1)




黃怡靜
Janet Huang
2012.05.01
Three main things today...
   - How to show an image in iPhone/iPad?
   - How to change an images on touch?
   - How to create animation with multiple
   images?


Other one thing...
    - Testing multitouch using tangible object
http://www.openframeworks.cc/



openFrameworks is an open source C++
toolkit for creative coding.




                                http://www.delicious.com/stacks/view/Fuhl88
OF component
iPhone/iPad application using OF

                        using c++

      iPhone/iPad app

           main.mm
                                declaration
          testApp.h             (parameter, method)


         testApp.mm             implementation
How to start?
  1. create a copy of emptyExample in apps folder
  2. rename the folder and .xcodeproj file
  3. open the project
  4. rename target
  5. make sure it builds and runs



                put your project in the right position
#pragma once

#include "ofMain.h"
#include "ofxiPhone.h"
#include "ofxiPhoneExtras.h"

class testApp : public ofxiPhoneApp {
!
public:
! void setup();
! void update();
! void draw();
! void exit();
!
! void touchDown(ofTouchEventArgs &touch);
! void touchMoved(ofTouchEventArgs &touch);
! void touchUp(ofTouchEventArgs &touch);
! void touchDoubleTap(ofTouchEventArgs &touch);
! void touchCancelled(ofTouchEventArgs &touch);

!    void   lostFocus();
!    void   gotFocus();
!    void   gotMemoryWarning();
!    void   deviceOrientationChanged(int newOrientation);

};




                                                            testApp.h
#include "testApp.h"

//--------------------------------------------------------------
void testApp::setup(){!
! // register touch events
                                                                   setup
! ofRegisterTouchEvents(this);
!
! // initialize the accelerometer           execute only once
! ofxAccelerometer.setup();
!
! //iPhoneAlerts will be sent to this.
! ofxiPhoneAlerts.addListener(this);
!
! //If you want a landscape oreintation
! //iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT);
!
! ofBackground(127,127,127);
}

//--------------------------------------------------------------

                                                   loop            update
void testApp::update(){

}

//--------------------------------------------------------------

                                                   loop            draw
void testApp::draw(){
!
}

//--------------------------------------------------------------
void testApp::exit(){

}

                                                               testApp.mm
//--------------------------------------------------------------
void testApp::touchDown(ofTouchEventArgs &touch){

}
                                                               touch event
//--------------------------------------------------------------
void testApp::touchMoved(ofTouchEventArgs &touch){

}

//--------------------------------------------------------------
void testApp::touchUp(ofTouchEventArgs &touch){

}

//--------------------------------------------------------------
void testApp::touchDoubleTap(ofTouchEventArgs &touch){

}

//--------------------------------------------------------------
void testApp::lostFocus(){

}
                                                               alert handler
//--------------------------------------------------------------
void testApp::gotFocus(){

}

//--------------------------------------------------------------
void testApp::gotMemoryWarning(){

}

//--------------------------------------------------------------
void testApp::deviceOrientationChanged(int newOrientation){

}


//--------------------------------------------------------------

                                                                   testApp.mm
void testApp::touchCancelled(ofTouchEventArgs& args){

}
Try to build and run an emptyExample
iPhone/iPad screenshots

                                iPad
                                screen size: 1024x768
                                resolution: 72 ppi
                                icon size: 72x72 px




                  iPhone
                  screen size: 320x480 (640x960)
                  resolution: 72 ppi
                  icon size: 57x57 px
Orientations




         Portrait        Upside Down




        Landscape Left    Landscape Right
1. show an image

  testApp.h
          ofImage myImage;

  testApp.mm                                               setup()

          myImage.loadImage("images/creature1.png");


           ofEnableAlphaBlending();
           myImage.draw(100, 100);
                                                     draw()
  image type: PNG, JPEG, TIFF, BMP, GIF
  position: [project]/bin/data/
       http://www.openframeworks.cc/documentation/graphics/ofImage_.html
1024

      (0,0)
768              (100,100)



                                   image height




                     image width
2. change an image on touch
                                           checking flag
   - bool touched (true / false)
     touched = false;
     imageA.loadImage("images/creature1.png");
     imageB.loadImage("images/creature3.png");     setup()

      void testApp::draw(){
      ! if(touched)
              imageA.draw(100,100);
          else
              imageB.draw(100,100);
      }

      void testApp::touchDown(ofTouchEventArgs &touch){
          touched = true;
      }

      void testApp::touchUp(ofTouchEventArgs &touch){
          touched = false;
      }
Array              index

       x[0] x[1] x[2] x[3] x[4]
                                                                     value


   4           2                13            1                  5

  int x[5]; declare a array x
  x[0] = 4 assign value into array x   OR             int x[5] = {4, 2, 13, 1, 5};
  x[1] = 2
  x[2] = 13
  x[3] = 1
  x[4] = 5                             John       Amy       Mike      Cindy   David

                                        0         1          2          3       4
For-loop

                    initial   condition   addendum
            for (int i = 0; i < 10; i++) {

                 printf("Hi: %i", i);

            }




   print array x
     for (int i = 0; i < 5; i++) {

           printf("print x[%i]= %i", x[i]);

     }
3. create animations using multiple images


        x[0] x[1] x[2] x[3] x[4]




   image1    image2      image3    image4    image5




   #define BACKFRAMENUM 10
                                     number of images

   ofImage backImage[BACKFRAMENUM];
for (int i = 0; i < BACKFRAMENUM; i++) {
        char char1[32];                              setup()
         sprintf(char1, "images/background%d.png", i+1);
         backImage[i].loadImage(char1);
    }




void testApp::draw(){
!
    ofEnableAlphaBlending();
    backImage[currentFrame].draw(0, 0);
                                                    draw()
        currentFrame++;
        if (currentFrame > BACKFRAMENUM - 1)
            currentFrame = 0;

}

Weitere ähnliche Inhalte

Was ist angesagt?

Was ist angesagt? (8)

Graphics programs
Graphics programsGraphics programs
Graphics programs
 
TensorFlow 深度學習快速上手班--電腦視覺應用
TensorFlow 深度學習快速上手班--電腦視覺應用TensorFlow 深度學習快速上手班--電腦視覺應用
TensorFlow 深度學習快速上手班--電腦視覺應用
 
The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210The Ring programming language version 1.9 book - Part 65 of 210
The Ring programming language version 1.9 book - Part 65 of 210
 
Quality Python Homework Help
Quality Python Homework HelpQuality Python Homework Help
Quality Python Homework Help
 
My favorite slides
My favorite slidesMy favorite slides
My favorite slides
 
TDD per Webapps
TDD per WebappsTDD per Webapps
TDD per Webapps
 
Snapshot testing by Anna Doubkova
Snapshot testing by Anna Doubkova Snapshot testing by Anna Doubkova
Snapshot testing by Anna Doubkova
 
OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2OPERATOR IN PYTHON-PART2
OPERATOR IN PYTHON-PART2
 

Ähnlich wie Of class1

2011 py con
2011 py con2011 py con
2011 py con
Eing Ong
 
2010 bb dev con
2010 bb dev con 2010 bb dev con
2010 bb dev con
Eing Ong
 
write a MATLAB GUI program that implements an ultrasound image viewi.pdf
write a MATLAB GUI program that implements an ultrasound image viewi.pdfwrite a MATLAB GUI program that implements an ultrasound image viewi.pdf
write a MATLAB GUI program that implements an ultrasound image viewi.pdf
footstatus
 
A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
Chu Lam
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
roxlu
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
Susan Gold
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
Adil Jafri
 

Ähnlich wie Of class1 (20)

Of class2
Of class2Of class2
Of class2
 
2011 py con
2011 py con2011 py con
2011 py con
 
2010 bb dev con
2010 bb dev con 2010 bb dev con
2010 bb dev con
 
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
XebiCon'17 : Faites chauffer les neurones de votre Smartphone avec du Deep Le...
 
HTML5って必要?
HTML5って必要?HTML5って必要?
HTML5って必要?
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
write a MATLAB GUI program that implements an ultrasound image viewi.pdf
write a MATLAB GUI program that implements an ultrasound image viewi.pdfwrite a MATLAB GUI program that implements an ultrasound image viewi.pdf
write a MATLAB GUI program that implements an ultrasound image viewi.pdf
 
Real life XNA
Real life XNAReal life XNA
Real life XNA
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGL
 
Java awt
Java awtJava awt
Java awt
 
A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
"Quantum" performance effects
"Quantum" performance effects"Quantum" performance effects
"Quantum" performance effects
 
Gdc09 Minigames
Gdc09 MinigamesGdc09 Minigames
Gdc09 Minigames
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)Useful Tools for Making Video Games - XNA (2008)
Useful Tools for Making Video Games - XNA (2008)
 
Android workshop
Android workshopAndroid workshop
Android workshop
 
Of class3
Of class3Of class3
Of class3
 
mobl
moblmobl
mobl
 

Mehr von Janet Huang (10)

Transferring Sensing to a Mixed Virtual and Physical Experience
Transferring Sensing to a Mixed Virtual and Physical ExperienceTransferring Sensing to a Mixed Virtual and Physical Experience
Transferring Sensing to a Mixed Virtual and Physical Experience
 
Collecting a Image Label from Crowds Using Amazon Mechanical Turk
Collecting a Image Label from Crowds Using Amazon Mechanical TurkCollecting a Image Label from Crowds Using Amazon Mechanical Turk
Collecting a Image Label from Crowds Using Amazon Mechanical Turk
 
Art in the Crowd
Art in the CrowdArt in the Crowd
Art in the Crowd
 
How to Program SmartThings
How to Program SmartThingsHow to Program SmartThings
How to Program SmartThings
 
Designing physical and digital experience in social web
Designing physical and digital experience in social webDesigning physical and digital experience in social web
Designing physical and digital experience in social web
 
Iphone course 3
Iphone course 3Iphone course 3
Iphone course 3
 
Iphone course 2
Iphone course 2Iphone course 2
Iphone course 2
 
Iphone course 1
Iphone course 1Iphone course 1
Iphone course 1
 
The power of example
The power of exampleThe power of example
The power of example
 
Responsive web design
Responsive web designResponsive web design
Responsive web design
 

Kürzlich hochgeladen

Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Kürzlich hochgeladen (20)

Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 

Of class1

  • 1. Openframeworks x iPad Game Design (1) 黃怡靜 Janet Huang 2012.05.01
  • 2. Three main things today... - How to show an image in iPhone/iPad? - How to change an images on touch? - How to create animation with multiple images? Other one thing... - Testing multitouch using tangible object
  • 3. http://www.openframeworks.cc/ openFrameworks is an open source C++ toolkit for creative coding. http://www.delicious.com/stacks/view/Fuhl88
  • 5. iPhone/iPad application using OF using c++ iPhone/iPad app main.mm declaration testApp.h (parameter, method) testApp.mm implementation
  • 6. How to start? 1. create a copy of emptyExample in apps folder 2. rename the folder and .xcodeproj file 3. open the project 4. rename target 5. make sure it builds and runs put your project in the right position
  • 7. #pragma once #include "ofMain.h" #include "ofxiPhone.h" #include "ofxiPhoneExtras.h" class testApp : public ofxiPhoneApp { ! public: ! void setup(); ! void update(); ! void draw(); ! void exit(); ! ! void touchDown(ofTouchEventArgs &touch); ! void touchMoved(ofTouchEventArgs &touch); ! void touchUp(ofTouchEventArgs &touch); ! void touchDoubleTap(ofTouchEventArgs &touch); ! void touchCancelled(ofTouchEventArgs &touch); ! void lostFocus(); ! void gotFocus(); ! void gotMemoryWarning(); ! void deviceOrientationChanged(int newOrientation); }; testApp.h
  • 8. #include "testApp.h" //-------------------------------------------------------------- void testApp::setup(){! ! // register touch events setup ! ofRegisterTouchEvents(this); ! ! // initialize the accelerometer execute only once ! ofxAccelerometer.setup(); ! ! //iPhoneAlerts will be sent to this. ! ofxiPhoneAlerts.addListener(this); ! ! //If you want a landscape oreintation ! //iPhoneSetOrientation(OFXIPHONE_ORIENTATION_LANDSCAPE_RIGHT); ! ! ofBackground(127,127,127); } //-------------------------------------------------------------- loop update void testApp::update(){ } //-------------------------------------------------------------- loop draw void testApp::draw(){ ! } //-------------------------------------------------------------- void testApp::exit(){ } testApp.mm
  • 9. //-------------------------------------------------------------- void testApp::touchDown(ofTouchEventArgs &touch){ } touch event //-------------------------------------------------------------- void testApp::touchMoved(ofTouchEventArgs &touch){ } //-------------------------------------------------------------- void testApp::touchUp(ofTouchEventArgs &touch){ } //-------------------------------------------------------------- void testApp::touchDoubleTap(ofTouchEventArgs &touch){ } //-------------------------------------------------------------- void testApp::lostFocus(){ } alert handler //-------------------------------------------------------------- void testApp::gotFocus(){ } //-------------------------------------------------------------- void testApp::gotMemoryWarning(){ } //-------------------------------------------------------------- void testApp::deviceOrientationChanged(int newOrientation){ } //-------------------------------------------------------------- testApp.mm void testApp::touchCancelled(ofTouchEventArgs& args){ }
  • 10. Try to build and run an emptyExample
  • 11. iPhone/iPad screenshots iPad screen size: 1024x768 resolution: 72 ppi icon size: 72x72 px iPhone screen size: 320x480 (640x960) resolution: 72 ppi icon size: 57x57 px
  • 12. Orientations Portrait Upside Down Landscape Left Landscape Right
  • 13. 1. show an image testApp.h ofImage myImage; testApp.mm setup() myImage.loadImage("images/creature1.png"); ofEnableAlphaBlending(); myImage.draw(100, 100); draw() image type: PNG, JPEG, TIFF, BMP, GIF position: [project]/bin/data/ http://www.openframeworks.cc/documentation/graphics/ofImage_.html
  • 14. 1024 (0,0) 768 (100,100) image height image width
  • 15. 2. change an image on touch checking flag - bool touched (true / false) touched = false; imageA.loadImage("images/creature1.png"); imageB.loadImage("images/creature3.png"); setup() void testApp::draw(){ ! if(touched) imageA.draw(100,100); else imageB.draw(100,100); } void testApp::touchDown(ofTouchEventArgs &touch){ touched = true; } void testApp::touchUp(ofTouchEventArgs &touch){ touched = false; }
  • 16. Array index x[0] x[1] x[2] x[3] x[4] value 4 2 13 1 5 int x[5]; declare a array x x[0] = 4 assign value into array x OR int x[5] = {4, 2, 13, 1, 5}; x[1] = 2 x[2] = 13 x[3] = 1 x[4] = 5 John Amy Mike Cindy David 0 1 2 3 4
  • 17. For-loop initial condition addendum for (int i = 0; i < 10; i++) { printf("Hi: %i", i); } print array x for (int i = 0; i < 5; i++) { printf("print x[%i]= %i", x[i]); }
  • 18. 3. create animations using multiple images x[0] x[1] x[2] x[3] x[4] image1 image2 image3 image4 image5 #define BACKFRAMENUM 10 number of images ofImage backImage[BACKFRAMENUM];
  • 19. for (int i = 0; i < BACKFRAMENUM; i++) { char char1[32]; setup() sprintf(char1, "images/background%d.png", i+1); backImage[i].loadImage(char1); } void testApp::draw(){ ! ofEnableAlphaBlending(); backImage[currentFrame].draw(0, 0); draw() currentFrame++; if (currentFrame > BACKFRAMENUM - 1) currentFrame = 0; }