Sprite Animation 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

Table Views UITableView. Overview Table view basics Tables display lists of data Each item in a tables list is a row Tables can have an unlimited number.
Whats New in Office 2010?. Major Changes in Office 2010 The Office Ribbon, which first made its appearance in Office 2007, now appears in all Office 2010.
BTEC 149. Windows Desktop Click on the Start Button.
Detecting Collisions CSE 391 Fall 2012 Tony Scarlatos.
Create a calculator– 2nd iPhone programming exercise CSE 391 Fall 2012.
Creating Animations – Lesson 71 Creating Animations Lesson 7.
Introduction to TouchDevelop
Introduction to Objective-C and Xcode (Part 1) FA 175 Intro to Mobile App Development.
The Accelerometer CSE 391 Fall 2011 Tony Scarlatos.
App Inventor Barb Ericson July 3, 2013.
The Problem: iPhone UI Navigation I want to have a TableView that works INSIDE a TabView.
View Controllers (second part) Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
METHODS!.  A method is a sequence of instructions or behaviors that will be carried out when requested.  You can use them to create new methods so that.
Storyboards Managing multiple views. Overview Create a single view application Give the project a name and click “Use Storyboards” and “Use Automatic.
Animation Your Task. You must work in pairs. One of you will read these instruction and explain them, while the other person carries them out. Discuss.
® IBM Software Group © 2006 IBM Corporation JSF Tab Controls This Learning Module shows how to develop server-side EGL applications with dynamic content.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Creating a MagicInfo Pro Screen Template
MrsBillinghurst. net A2 Computing A2 Computing Projects Game Animation in Pascal.
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
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.
What is Director?  A tool for creating interactive CDs or interactive media and games on the Web.  Combines graphics, sound, video and other media together.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Xcode testing Using XCTest.
Powerpoint Pizzaz! Table of Contents: Linking to a WebPageAdding Narration Linking to a DocumentSlide Show Set Up Linking to Another SlideWord Art Adding.
Multimedia- Microsoft PowerPoint
Intro to the Xcode IDE and the iOS SDK CSE 391 Fall 2012 Tony Scarlatos.
Flash Lesson 1 Simple Animation. Get Acquainted With The Software.
VIDEO GAME PROGRAMMING Video Game Programming Level One – Breakout INSTRUCTOR Big Dan Teague TEACHER’S ASSISTANT Delmar O'Donnell.
iOS components in Swift
Sharepoint Getting started. Please log on to the Adult and Family Education website: adulted.d11.org Then go to AFE Teaching Staff and click on Valerie.
Chapter 6 Publishing to the iPad. Installing Software for Working with the iPad When you create layout in InDesign, you can use the Adobe Content Viewer.
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
Computing Fundamentals Module Lesson 3 — Changing Settings and Customizing the Desktop Computer Literacy BASICS.
Adobe Flash CS3 Revealed Chapter 3 - WORKING WITH SYMBOLS AND INTERACTIVITY.
Lesson 11: Looking at Files and Folders what a file or folder is on the computer how to recognize a file or folder on the desktop how to recognize the.
Tabbed Views UITabBarController. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and.
How to use the timing feature Click to choose a shape, then click on the screen and drag it to place in on the slide.
Navigation in iPads splitViewController. Overview Create a Master-Detail application Switch Device Family to iPad Give the project a name and click “Use.
IOS with Swift Hello world app.
Using Xcode A Beginner’s Tutorial Erin Green. This tutorial will walk you through Xcode, a software development tool for Apple’s iOS applications – We.
Managing Multiple Views and Segues FA 172 Intro to Mobile App Development.
View Controllers Content taken from book: “iPhone SDK Development” by Bill Dudney and Chris Adamson.
Animating GIF. What is it? Think of how a flip book works. Each page is a different picture and when flipped through quickly, it looks as though objects.
Microsoft PowerPoint Research: Third- Fifth Grade
Creating a rotating image banner Activity 7 Procedure Creating AP Elements 1.Start Dreamweaver and select the ‘Hong Kong Scenery’ web site. 2. Create a.
Introduction to Objective-C and Xcode (Part 5) FA 175 Intro to Mobile App Development.
Sounds, Images, and Text FA 172 Intro to Mobile App Development.
Creating a Historical Tour in Alice By Jenna Hayes May 2010.
Making Folders (Revised 5/27/10) Adding/Editing Local Gallery Folders By Elizabeth Liang under the direction of Professor Susan Rodger Duke University.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Touch screen function manual Right & left scroll key Room selecting key, Maximal quantity 50. Controlling Target icon Room background image brightness.
Tutorial for Arrays and Lists. Description This presentation will cover the basics of using Arrays and Lists in an Alice world It uses a set of chickens.
Lecture 10 Using Interface Builder to create Mac Applications.
Photoshop Actions Lights, Camera, Actions in Photoshop.
Introduction to Objective-C and Xcode (Part 4) FA 175 Intro to Mobile App Development.
Madlib-Input, Strings, and Lists in Scratch Barb Ericson Georgia Tech.
Dreamweaver MX. 2 Timeline Overview (p. 480) n Animations can be achieved with DHTML (__________ HTML) using JavaScript code and _____ or later browsers.
WebViews UIWebView. Controller Architecture UITabBarController Controls the first view that the user sees The view controller class (and xib) that manages.
Flash Slideshow with Fade Transition Slideshow #1-Themed Images Slideshow #2-Instructional Images.
Weebly Elements, Continued
EEC-492/693/793 iPhone Application Development
Chapter 15, Images …a few points
CSC 581: Mobile App Development
Apple Xcode with Swift Demo
EEC-492/693/793 iPhone Application Development
Creating a Simple Game in Scratch
Presentation transcript:

Sprite Animation CSE 391 Fall 2012 Tony Scarlatos

Getting started The goal of this demo is to show you how to create an animation loop inside of an image object, and to then animate that image object across the screen. To do this we’ll need to learn how to create and then populate an array of images. We’ll also learn how to force an iPhone app to display in landscape mode.

Develop resources For this demo I created an animation of a walk cycle for a character using Poser, a 3D character animation software package. The animation was rendered as 15 still images at 320 X 240 resolution (.png format) with an alpha (transparent) background. I also chose a background that was 640 X 480.

Create the project 1.In Xcode create a Single View Application, name it and save it (I named my project Boneyard). 2.In the Summary tab deselect the Portrait orientation icon. 3.Drag and drop your images to the Supporting Files folder, remembering to check that they should be copied to the destination folder. I had to rename the animation frames b01.png, b02.png, b03.png … for a reason I’ll explain later. 4.To clean up the Supporting Files folder select File > New > New Group. Now you can place all the images in that folder. You can name it “images”.

Adding assets

Define a method header In the ViewController.h file (from the Classes folder) I defined an image object (walk) and an array (anim), and established their properties. I also defined a method for moving the object called move. The NSMutableArray class simply means the dimensions of the array can change. The code looks like this: boneyardViewController : UIViewController { } (nonatomic, strong) IBOutlet UIImageView (nonatomic, strong) NSMutableArray *anim; // A method to move the animated object... -(void)

Set up the interface 1.Click the Main.storyboard file to open Interface Builder (IB). 2.Rotate the View window to landscape mode. You can do this by choosing Orientation > Landscape in the View Attributes tab of the Inspector window. 3.Bring in the background image object by dragging it from the Library to the View, and let it fill the View. You can add an image to it by selecting the image from the dropdown list in the Image View Attributes tab of the Inspector. 4.Add a second UIImage object to the View. I set the size of the object at 240 X 180 in the View Size tab of the Inspector. The default image for the object was b01.png which I selected from the dropdown list in the Image View Attributes tab of the Inspector.

Connect the method to the object Select File’s Owner from the Document window. From the Outlets tab in the Inspector, drag a line from the circle to the right of the name of your outlet (I called mine walk) to the image object that will display your animation (not the background image). The setting for the image object should be “Scale To Fill”. In my case, the “Opaque” setting for the image had to be unchecked, so that the image’s alpha channel would reveal the background.

Populate the image array In order to execute the code that will populate the image array and play the images sequentially we need an event. Like we did before, we will use the viewDidLoad method, and that will act as our trigger. We begin by initializing the array in the first line of code. In the second line of code we create a for loop that will iterate through our array. The third line of code creates a string that substitutes the value of i for the %d variable in the image name Thus it will generate b01.png to b15.png. The fourth line of code assigns those items to the UIIMage object, and the fifth line of code imports the images to the array. The code is on the following slide.

The for loop anim=[[NSMutableArray alloc] init]; // A for loop is used instead of a list of each picture in the array. for(int i=0;i<15;i++){ NSString *pic=[NSString i]; UIImage *img=[UIImage imageNamed:pic]; if (img)[anim addObject:img]; }

Play the images The next three lines of code do the animating. They are added below the code we just inserted in the viewDidLoad method. In my example, the first line assigns the array of images (anim) to the UIImage object (walk). The second line sets the duration of each image’s display. Larger values display each image for longer, slowing the animation down. Smaller values speed the animation up. The last line starts the animation. The code is below: [_walk setAnimationImages:_anim]; [_walk setAnimationDuration:.75]; [_walk startAnimating];

Move the image object across the screen To move the object across the screen continuously we’ll need to set a timer as we did before. The timer will spawn a thread that will execute the move method defined in the.h file. Right above the code we wrote in the viewDidLoad method (where we initialized the array) we will add 2 more lines of code. The first line sets the duration of the timer and triggers the move method at the end of the timer. It also tells the timer to repeat indefinitely. The second line of code just executes the move method the first time so there is no delay starting the animation. The value of the duration of the timer, of course, will vary with the animation you intend to do. The code is on the following slide.

Timer code [NSTimer scheduledTimerWithTimeInterval:17 target:self userInfo:nil repeats:YES]; [self move];

Implement the move method Finally, in the.m file, just above statement we can implement the move method. The first and fifth lines of code define the start and end points of the animation, by defining the CGRect (window) of the animation. The first 2 values are the position of the window (x and y), and the second two values are the dimensions of the window. The third line of code sets the duration of the animation (which of course will vary depending on the project), and the last line of code commits the animation. Note the timer value in my project was 17, and the animation duration in the move method is The code appears on the next slide.

The move method -(void) move { walk.frame=CGRectMake(-140,80,240,180); [UIView animateWithDuration:16.5 animations:^{ _walk.frame=CGRectMake(self.view.frame.size.width- 60,80,240,180); }];}

Success!