Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.

Slides:



Advertisements
Similar presentations
View-Based Application Development Lecture 1 1. Flows of Lecture 1 Before Lab Introduction to the Game to be developed in this workshop Comparison between.
Advertisements

Lesson 5+: Using He- Builder/She-Builder And Adding Text! Slides are adapted from aliceprogramming.net or
Using Eclipse. Getting Started There are three ways to create a Java project: 1:Select File > New > Project, 2 Select the arrow of the button in the upper.
Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.
Google Apps: Google Mail Got Gmail?....Need Help? Mrs. Connor.
How to make a game on game maker 7. Start With an Idea Before you actually start making your game, you are going to need an idea as to what it is you.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Google Earth How to create a Google Earth Tour and place it in your Wiki.
Programming with App Inventor Computing Institute for K-12 Teachers Summer 2012 Workshop.
Adding Websites to a Folder  Putting sites into an already existing folder Putting sites into an already existing folder  Adding an image on the icon.
Sprite Animation CSE 391 Fall 2012 Tony Scarlatos.
Chapter 3 Working with Symbols and Interactivity.
05/09/ Introducing Visual Basic Sequence Programming.
Simple Game Animation – iPhone Programming Exercise 3 CSE 391 Fall 2012 Tony Scarlatos.
Xcode Presentation Tom Pletzke. Creating App from template Launch Xcode Select Tabbed Application.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
Intro to the Xcode IDE and the iOS SDK CSE 391 Fall 2012 Tony Scarlatos.
Chapter 1 P. 1 Writing Windows applications with Visual Basic Figure 1.1 The first program works as follows: (These operations can be performed in any.
PowerPoint 1 The Basics 1. Save this file to your Apps Folder as YourLastName_PP1 2. Read each slide. 3. Complete each set of numbered directions.
Chapter 3 Introducing Visual Basic.NET. 3.1 Visual Basic.NET Windows Programming -Used to create Windows, Web, and Console applications -Uses predefined.
Making a PowerPoint Slide By Ms. Wesley. Creating Your PowerPoint Slide Learn how to: – Open PowerPoint ………………………….…….………Slides 3, 4Open PowerPoint –
iOS components in Swift
Using the Netbeans GUI Builder. The Netbeans IDE provides a utility called the GUI Builder that assists you with creating Windows applications. The Netbeans.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
1 Designing with a UIToolBar iPhone/iPad, iOS Development Tutorial.
 Application – another name for a program.  Interface – is what appears on the screen when the application is running.  Program Code – is instructions.
Photo Story 3 Importing Pictures. When you create a new Photo Story, the first thing that you will do is import pictures. You can import pictures from.
Using Lycos TRIPOD Create Your Own Website. Go to the Lycos Tripod website located at address:
Adding Documents to OnCourse. Add a Document Look for the Documents tab and click it.
Adobe Flash CS3 Revealed Chapter 3 - WORKING WITH SYMBOLS AND INTERACTIVITY.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
Office Management Tools II Ms Saima Gul. Office Management Tools II Ms Saima Gul.
IOS with Swift Hello world app.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Gestures UIGestureRecognizer.
Applications Development
Nav Controllers UINavigationController. Overview Nav Controller basics Like a tabview controller, a navViewController manages views A navigationViewController.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Lecture 10 Using Interface Builder to create Mac Applications.
1. 2 Download Windows Media Player 10: Download PhotoStory3
Know your computer Make a Folder Copy from Word to Composer Format the Font Change the Alignment Format the Background Format the Colors Insert a Picture.
BBT 10 Visual Basic 03 Enrichment. Tip Before creating any files for your project, first create a new folder Save all of your files in the folder Pieces.
Inserting Hyperlinks  Purpose : Enables viewers to click the link and move directly to a slide  Directions : Make one link on slide one to move to each.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 3 Building an Application in the Visual Basic.NET Environment.
If you don’t have Google Earth downloaded already, you can go to to get it.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Metadata is simply, data about data. Several types of data and personal information can be saved in a Word document. This information might not be immediately.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Spinning Circle.
Open a BLANK WORD document
Using PowerPoint to Scaffold a Text
Using a set-up file to read ASCII data into SPSS
EEC-492/693/793 iPhone Application Development
Chapter 1 Editing a Photo
EEC-492/693/793 iPhone Application Development
EEC-492/693/793 iPhone Application Development
CIS16 Application Development Programming with Visual Basic
Working with Symbols and Interactivity
Making Pictures Come to Life...
Goto “\\ \utilities\Virus_Sfw\Patches”
EVENT TITLE Time, Date Location
EVENT TITLE Time, Date Location
Click to edit title TO ADD NEW SLIDE LAYOUTS: Make sure you have the ‘Home’ tab selected at the top of the PowerPoint screen and click the down facing.
EEC-492/693/793 iPhone Application Development
Legacy PowerPoint Slides
Presentation transcript:

Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos

Create a new project Just to do something different this time, let’s create a Utility Application. It has a built-in feature, the flipside view, that we’ll use to confirm that the collision of our 2 image objects was successfully detected. First, create a couple of images to use. As we have done before, add them to the Supporting Files folder of the Xcode Utility Application you just created.

Set up the MainViewController.h file There are 2 views in a Utility app – the main view and the flipside view. In the project folder open up the MainViewController.h file. We’ll need to declare 2 image objects and their properties. We’ll also need to create a method called checkCollision. One method is already given to us – an IB action called showInfo – which will reveal the flipside view. The code is on the following slide. When you have written the code, click the MainView.xib file to launch Interface Builder.

Create the image objects #import MainViewController : UIViewController { (nonatomic, strong) IBOutlet UIImageView (nonatomic, strong) IBOutlet UIImageView *image2; -(void)

Set up your interface In Interface Builder you’ll notice an info icon (an “i” set in a circle) in the lower right of the View window, which you can select and delete. It’s actually a built-in button that triggers the flipside view, but we’ll be using a conditional statement to do that. Change the background color of the View if you wish from the Inspector window’s Attributes tab. Drag in 2 Image Views. I scaled them to 100 X 100 using the Inspector’s View Size tab. I placed one Image View near the top of the screen and the other near the bottom. Select each Image View and load the appropriate image using the dropdown list in the Attributes tab.

Remove Flipside View button

Make connections Select File’s Owner from the Document window. In the Inspector’s Connections tab, drag a line from the image1 method’s connector to your top Image View, and drag a connection for the image2 method to the bottom Image View. Save your Main.storyboard file and return to Xcode.

Implementation In the MainViewController.m file, we will need to set up a touch event. We’ll do this right after statement. The first line sets up the touch event, the second line assigns it to an instance called myTouch, and the third line moves the image1 object to the location of the touch in the View (based on the center of the object’s bounding box). The last line calls the checkCollision method each time a touch event occurs. The code is on the following slide.

The touch event -(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *myTouch = [[event allTouches] anyObject]; _image1.center = [myTouch locationInView:self.view]; [self checkCollision]; }

Checking for a collision Now we’ll implement the checkCollision method. The first line is a conditional statement that looks for an overlap of the frames (bounding boxes) of the image1 and image2 objects. If the objects overlap, the methods within the curly braces will execute. The actual method, FlipsideViewController, was copied from the IBAction showInfo code block farther down in the.m file. In effect this tells the app to flip the view when a collision is detected. The last line of the code simply resets the image1 object to its original position. The code is on the following slide.

The conditional statement -(void) checkCollision { if(CGRectIntersectsRect(image1.frame, image2.frame)) { [self sender:self]; image1.frame=CGRectMake(100,20,100,100); }

Creating the Segue

Build the flipside view Click FlipsideViewController in the Interface Builder. There isn’t much you have to do here. You can give the View a title, or you delete the text in the title bar. I dragged a label into the View that says “Happy Halloween!” Click Run in Xcode.

Success!