CSE 190 M Flash Sessions Session 2 Alex Miller, Spring 2011.

Slides:



Advertisements
Similar presentations
Chapter 14 Graph class design Bjarne Stroustrup
Advertisements

Creative Computing. Comments on Assignments Everyone did very well Report writing needs more work Jumping scale Update first then draw.
Introduction to Macromedia Director 8.5 – Lingo
1What is the Stage. 2How do you open a panel in Flash
18/2/00SEM107 - © Kamin & Reddy Class 7 - LineList - 1 Class 7 - Line Drawings  The LineList data type r Recursive methods to construct line drawings.
Building Java Programs
Mouse Listeners We continue our examination of GUIs by looking at how to interact with the mouse –Just as Java creates Events when the user interacts with.
© Calvin College, Being abstract is something profoundly different from being vague... The purpose of abstraction is not to be vague, but to create.
Return values.
C++ is Fun – Part 10 at Turbine/Warner Bros.! Russell Hanson.
Chapter 5 Programming Graphics. Chapter Goals To be able to write applications with simple graphical user interfaces To display graphical shapes such.
Chapter 14 Graph class design John Keyser’s Modifications of Slides by Bjarne Stroustrup
Program Design. Objectives Students should understand the basic steps in the programming process. Students should understand the need for good design.
Mission Technology Introduction to Scratch! June 2007.
 2004 Prentice Hall, Inc. All rights reserved. Chapter 18 – Macromedia Flash MX 2004: Building an Interactive Game Outline 18.1 Introduction 18.2 Object-Oriented.
Roy McElmurry. ActionScript : an object-oriented programming language similar to JavaScript MXML : A flavor of XML that helps simplify user interface.
Scratch Programming Session 6 of 10 If-then-else statements interactions Final projects specifications.
Copyright 2006 by Pearson Education 1 Building Java Programs Chapter 3: Parameters, Return, and Interactive Programs with Scanner.
Introduction to Macromedia Flash 8
1 Data types, operations, and expressions Continued l Overview l Assignment statement l Increment and Decrement operators l Short hand operators l The.
PROCESSING Animation. Objectives Be able to create Processing animations Be able to create interactive Processing programs.
Microsoft® Small Basic The Math Object Estimated time to complete this lesson: 1 hour.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
1 CS101 Introduction to Computing Lecture 35 Mathematical Methods (Web Development Lecture 12)
2 What is pyGame? A set of Python modules to make it easier to write games. –home page: –documentation:
Guide to Programming with Python
Working with Numbers in Alice - Converting to integers and to strings - Rounding numbers. - Truncating Numbers Samantha Huerta under the direction of Professor.
Introduction to Scratch!
© 2011 Delmar, Cengage Learning Chapter 9 Introduction to ActionScript 3.0.
METHODS AND SCOPE CSCE More on Methods  This is chapter 6 in Small Java.
© 2012 Adobe Systems Incorporated. All Rights Reserved. Copyright 2012 Adobe Systems Incorporated. All rights reserved. ® INTRODUCTION TO FLASH ANIMATION.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 8 "The games of a people reveal.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 8 "The games of a.
Addison Wesley is an imprint of © 2010 Pearson Addison-Wesley. All rights reserved. Chapter 7 The Game Loop and Animation Starting Out with Games & Graphics.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Distributed Multimedia Programming Week - 1. Document Window  The Document Window is divided in to six main components Timeline – The Timeline is where.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script "The games of a people reveal.
2006 Adobe Systems Incorporated. All Rights Reserved. 1 INTRODUCTION TO ADOBE FLASH CS3.
ActionScript 3.0 Basic Programming Concepts by Martin Stanhope The University of Bolton.
CSE 190 M Flash Sessions Session 3 Alex Miller, Spring 2011.
Introduction to Flash Animation CS 318. Topics Introduction to Flash and animation The Flash development environment Creating Flash animations  Layers.
Game Maker Terminology
CIS 3.5 Lecture 2.2 More programming with "Processing"
CRE Programming Club Class 3 (Install Small Basic on the new computers! Double-click on I:/smallbasic.msi)
© 2011 Delmar, Cengage Learning Chapter 10 Using ActionScript to Enhance User Experience.
XP Tutorial 3 Creating Animations. XP New Perspectives on Macromedia Flash MX Elements of Animation Layers are used to organize the content of.
Intro to ActionScript CIS 126 Greg Shorts. What Is ActionScript? ActionScript is the scripting language Flash uses to control its movies and the objects.
Adventures in Animation Introduction to Scratch! Michelle Venable-Foster Barb Ericson Dec 2007.
Computer Science I Animations. Bouncing ball. The if statement. Classwork/homework: bouncing something. Compress and upload work to Moodle.
1 Computer Science of Graphics and Games MONT 105S, Spring 2009 Session 22 Game Graphics.
Session 7 More Implications of Inheritance & Chapter 5: Ball World Example.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script "The games of a people.
Flash Interface, Commands and Functions
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Building Java Programs
Actionscript Session 2 Roy McElmurry.
Topic 10 return values, Math methods
Building Java Programs
Java's Math class Method name Description Math.abs(value)
Building Java Programs
More programming with "Processing"
Topic 10 return values, Math methods
Building Java Programs
Tweening along a path.
Programming games Demonstrate cannonball
Building Java Programs
Presentation transcript:

CSE 190 M Flash Sessions Session 2 Alex Miller, Spring 2011

Loops & Conditionals for (var i:int = 0; i < 20; i++) { // code here } For loop while (x == 3) { // code here } While loop if (x == 3) { // code here } else if (x > 4) { // code here } else { // code here } If statement

JavaFlash int x = 42; double y = (double) x; Casting var x:int = 42; var y:Number = x as Number; Casting String x = “hello”; String y = “hello”; if (x.equals(y)) { //... } String equality var x:String = “hello”; var y:String = “hello”; if (x == y) { //... } Any others? public static final int MY_CONSTANT = 42; Constant public static const MY_CONSTANT:int = 42; Constant

Sprite  Sprites are our main graphical building block.  We can create a new empty Sprite: import flash.display.Sprite;... var mySprite:Sprite = new Sprite();  We can write classes that extend Sprite. Useful because we get a Graphics object for each Sprite.

Sprite ASDescription sprite.graphics Graphics object used to draw on the Sprite. sprite.x sprite.y The (x, y) coordinates of the Sprite. You can change these to move the Sprite. sprite.width sprite.height Width and height of the Sprite. sprite.addChild(child); Used to add other Sprites onto the Sprite. sprite.stage A reference to the “stage” for the Flash movie. sprite.visible Boolean that determines whether Sprite is visible or not. sprite.rotation Angle of rotation in degrees. Default is 0. sprite.alpha Value between 0 and 1 which indicates how transparent the sprite is.

MyProgram

truck addChild(truck); MyProgram

truck Confusing subtlety: Graphics draws shapes relative to the (x, y) position of the Sprite it’s attached to. MyProgram

Stage ASDescription stage.stageWidth stage.stageHeight Overall width and height of movie. stage.mouseX stage.mouseY Mouse (x, y) coordinates.  The main container for everything, even the document class Sprite.  All Sprites have a reference to the stage for the movie.  Holds information about the.swf movie:

Animation

 An animation consists of a series of frames.  Each frame is displayed on the screen for a short time (~50 times per second).  Creates the illusion of movement.

package { import flash.display.Sprite; import flash.events.Event; public class MyAnimatedProgram extends Sprite { public function MyAnimatedProgram():void { // setup code addEventListener(Event.ENTER_FRAME, onEnterFrame); } private function onEnterFrame(e:Event):void { // this code runs multiple times a second } Animation “Enter Frame” Event

Math ASDescription Math.abs(value); Returns absolute value of passed in value. Math.sin(value); Math.cos(value); Math.tan(value); Returns sin/cos/tan of value (radians). Math.atan(value); Math.atan2(y, x); Arctangent functions. Math.log(value); Returns the natural log of value. Math.max(value1, value2); Math.min(value1, value2); Returns the max/min of the two values. Math.pow(value1, value2); Math.sqrt(value); Power and square root functions. Math.round(value); Returns rounded value. Math.random(); Returns a pseudorandom number between 0 and 1. Math.PI, Math.E Constants for π and e.

Mouse interaction  We have access to the current (x, y) position of the mouse. We can set a Sprite’s position to those coordinates to make it follow the mouse.  This interaction doesn’t have a lot of “pop” to it. Can we make the motion “springy” or “bouncy”?  Instead of snapping the Sprite to the (x, y) position of the mouse every frame, we can apply a force to the Sprite in the direction of the mouse.  To give the motion a springy effect, the force we apply every frame can be proportional to the distance from the Sprite to the mouse. A large distance means a larger force is applied that frame; a smaller distance means a smaller force.

Mouse interaction Springy Mouse Follow

Mouse interaction Springy Mouse Follow

Mouse interaction Springy Mouse Follow

Mouse interaction Springy Mouse Follow

Mouse interaction Springy Mouse Follow

Mouse interaction Springy Mouse Follow 1.Calculate the x and y components of the displacement vector from the Sprite to the mouse. 2.Calculate the magnitude and angle of the displacement vector from dx and dy. 3.Calculate a force value based on the displacement magnitude. 4.Split the force into x and y components and add them to the x and y velocity components of the Sprite. dx dy You may remember from physics class that F = ma. But we don’t really care about mass, so to simplify things we’re just doing F = a. d

Next week!  Mouse clicks, key presses  Displaying text to the screen  Simple game programming