1 Flash Actionscript Animation. 2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create.

Slides:



Advertisements
Similar presentations
Flash animation For beginners. Lesson objectives To understand how to animate a ball To understand how to loop animations To learn how to use animation.
Advertisements

CIS 205—Web Design & Development Flash Chapter 3 Appendix B on Creating Animations.
© Anselm Spoerri Lecture 11 Flash –Build Flash Website with Animated Navigation Structure –Decide on Overall Navigation Layout, Import Images & Organize.
1 Flash Actionscript Adding Interactive Actions Variables.
1 Flash Actionscript Actionscript and Objects Control Structures.
Flash Actionscript Control Structures Arrays
1 Flash Actionscript Adding Interactive Actions. 2 ActionScript 3.0 ActionScript is the language you use to add interactivity to Flash applications, whether.
1 Flash Programming Introduction Script Assist. 2 Course Description This course concentrates on the teaching of Actionscript, the programming language.
© 2011 Delmar, Cengage Learning Chapter 8 Building Complex Animations.
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Animations Flash ActionScript Introduction to Thomas Lövgren
Chapter 3 Working with Symbols and Interactivity.
XP Tutorial 5 Buttons, Behaviors, and Sounds. XP New Perspectives on Macromedia Flash MX Buttons Interactive means that the user has some level.
Introduction to Flash FYS100 Creative Discovery in Digital Art Forms Spring 2007 Burg.
In.  This presentation will only make sense if you view it in presentation mode (hit F5). If you don’t do that there will be multiple slides that are.
Introduction to TouchDevelop
Click your mouse for next slide Flash – Introduction and Startup Many times on websites you will see animations of various sorts Many of these are created.
Exercise : Animated Navigation Structure in Flash 1.Develop Answers to “What did you learn in ITI program?” “What do you have to offer?” “What are your.
Flash MX II. Flash MX – Tweened Animation There are two methods for creating an animation sequence in Flash –Frame-by-frame animation –Tweened animation.
Lehigh University Introduction to Flash MX Sharmeen Mecklai.
Chapter 11 Adding Sound and Video. Chapter 11 Lessons 1.Work with sound 2.Specify synchronization options 3.Modify sounds 4.Use ActionScript with sound.
GAME:IT Junior Learning Game Maker: The Move Tab.
Learning Game Maker Studio:
© 2011 Delmar, Cengage Learning Chapter 3 Working with Symbols and Interactivity.
KeyListener and Keyboard Events Just as we can implement listeners to handle mouse events, we can do the same for keyboard events (keypresses) –to implement.
KeyListener and Keyboard Events Another type of listener listens for keyboard entry – the KeyListener which generates KeyEvents –to implement KeyListener,
© 2010 Delmar, Cengage Learning Chapter 3: Working with Symbols and Interactivity.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 2 "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 Flash drawing trick(s). Past due: Your completion of rock-paper-scissors) Classwork: Bouncing ball: read tutorial. Start coding.
Programming games Show your version of Bo the dog. Start cannonball Preview: video, audio work session (cannonball) Homework: Cannonball with ball in a.
Creating Buttons – Lesson 71 Creating Buttons Lesson 7.
Adobe Flash CS3 Revealed Chapter 3 - WORKING WITH SYMBOLS AND INTERACTIVITY.
CSC 361/661 Digital Media Spring 2010 Professor Burg.
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.
1. Press the New Layer Button 3. Double click names to re-name Ball & Shadow layers 2. Click to change to 12 fps Step 1.
Learning Unity. Getting Unity
Motion Tweening – Lesson 81 Motion Tweening Lesson 8.
Introduction to Flash CSC361/661 Digital Media Spring 2007 Burg.
Macromedia Flash 8 Revealed WORKING WITH SYMBOLS AND INTERACTIVITY.
Game Maker Galactic Mail Advanced Group: Complete Galactic Mail, then start developing an independent project.
Computer Game Design ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects.
Flash animation For beginners. homework Your homework is over two weeks so please write in each week of your planner for the next two weeks For homework.
Programming Games Show your rock-paper-scissors. Demonstrate bouncing ball. Demonstrate and examine Bo the dog. Homework: Modify Bo to make your own.
SCRIPT PROGRAMMING WITH FLASH Introductory Level 1.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Action Script 12 "The games of a people.
Video in Macromedia Flash (Optional) – Lesson 121 Video in Macromedia Flash (Optional) Lesson 12.
CIS 205—Web Design & Development Flash Chapter 3 Appendix on Using Buttons.
Open a new Flash File Action Script 2.0. Create a button like you did last lesson and name it Click to Play.
© 2011 Delmar, Cengage Learning Chapter 11 Adding Sound and Video.
AD 305 Electronic Visualization I : School of Art and Design : University of Illinois at Chicago : Spring 2007 Intro to Action Script 12 "The games of.
XP Tutorial 3 Creating Animations. XP New Perspectives on Macromedia Flash MX Elements of Animation Layers are used to organize the content of.
Integrating Components and Dynamic Text Boxes with the Animated Map– Lesson 101 Integrating Components and Dynamic Text Boxes with the Animated Map Lesson.
CIS 205—Web Design & Development Flash Chapter 3 Working with Symbols and Interactivity.
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.
Macromedia Flash MX Design Professional And Interactivity WORKING WITH SYMBOLS.
AD 206 Intermediate CG : School of Art and Design : University of Illinois at Chicago : Spring 2009 Intro to Action Script 11 "The games of a people reveal.
Dreamweaver MX. 2 Timeline Overview (p. 480) n Animations can be achieved with DHTML (__________ HTML) using JavaScript code and _____ or later browsers.
 Movieclip symbols are reusable pieces of flash animation  consisting usually of one or more graphic/button symbols  thus they are flash movies within.
Game Maker Tutorials Introduction Clickball IntroductionClickball Where is it? Shooting Where is it?Shooting.
Prof. Anselm SpoerriMultimedia Production Rutgers Lecture 11 Flash –Build Flash Website with Animated Navigation Structure –Decide on Overall.
Index Background Costumes Making object walk smoothly Controlling an object with the keyboard Control an object with the mouse Changing costume when hit.
Flash animation For beginners.
Animate Some more advanced concepts
Go to =>
Working with Symbols and Interactivity
MovieCLip Instances & ActionScript
Exercise : Animated Navigation Structure in Animate (= Flash)
So you want to be a Game Designer
Exercise : Animated Navigation Structure in Flash
Presentation transcript:

1 Flash Actionscript Animation

2 Introduction to Sprites We will now look at implementing Sprites in Flash. We should know enough after this to create our own games. Sprites in Flash are screen-based objects whose behaviour and actions are controlled by dedicated code that is integral to itself. In other words, the sprite is responsible for looking after itself.

3 Introduction to Sprites The sprite should be able to do three basic things of its own accord: 1. Move - move around in an intelligent way and know if it’s moving into areas where it shouldn’t be. We will handle all of this by altering movie clip properties. 2. Detect Collisions - there is a method associated with movie clips which can detect collisions for us. 3. Act Independently - Sprite should take care of its own behaviour without interference from the main program.

4 Controlling Movement There are a number of issues we need to consider when dealing with sprites. Start with control. This implies simulating intelligence and giving the impression that the sprite is aware of what’s going on around it. We do this by attaching behaviours to the sprite. This means that the sprite has characteristics associated with it that govern its behaviour. So for example the behaviour associated with the ball in Pong might simply be ‘keep moving in associated direction’.

5 Controlling Movement We would need to make this a little more complex in order to handle bouncing off walls. The important point is that the sprite controls its own behaviour. It is NOT the case that the game controls the sprite.

6 Controlling Movement The basic mode of operation of a sprite is something like this: 1. Set my movement as per my behaviour. 2. Check whether I’m breaking any rules. 3. If I’m breaking a rule, modify my behaviour as per the rules of my environment, otherwise move me as per my behaviour. 4. Go back to 1.

7 Controlling Movement In the case of the ball in Pong then breaking a rule might involve hitting the side wall in which case the consequent modification of behaviour would be to change the direction of the sprite. Let’s have a go at implementing something like this:

8 Controlling Movement 1. Open a new movie. Create a graphic symbol called circle. Create a new movie clip symbol called bouncing and drag an instance of circle into it (use the info panel to make sure that this is centered at (0,0). 2. Insert a new layer to the movie clip called actions. This should contain three key frames which have the following pieces of ActionScript associated with them. Frame 1: var xMove:Number=Math.floor((Math.random()*20)-10); var yMove:Number=Math.floor((Math.random()*20)-10); Frame 2: this.x += xMove; this.y += yMove; if(this.x<0) { xMove = 0 - xMove; this.x=0; } else if (this.x >= 550) { xMove = 0 - xMove; this.x = 550; }

9 Controlling Movement else if(this.y<0) { yMove = 0 - yMove; this.y=0; } else if (this.y >= 400) { yMove = 0 - yMove; this.y = 400; } Frame 3 gotoAndPlay(2); 3. Drag one or more instances of this onto the stage and test it.

10 Controlling Movement What’s happening here? The first frame sets up two variables xMove and yMove and sets them both to a random value between -10 and +10. Math.floor() rounds our number down to the closest integer. Math.random() retrieves a random float between 0 and 0.999…

11 Controlling Movement The second frame does two things. It adds xMove and yMove to the position of the ball. So suppose xMove was -5 and yMove was 10. Then it moves the ball 5 units to the left and 10 units down. It then checks the position of the ball to see if it has moved off the screen. If it has done so it changes the sign of xMove or yMove as appropriate. Where do the figures 400 and 550 come from => default size for the movie. Can change this.

12 Controlling Movement We could also get the main movie to generate the instances with a loop. Go to the main timeline, delete all instances of the movie clip except for one. Give it the instance name ball. Right click on the bouncing symbol in the Library and choose Linkage. Check ‘Export for Actionscript’. Then insert the following code into frame one of the main timeline.

13 Controlling Movement var counter:int = 10 while (counter>0) { var newBouncing = new bouncing(); addChild(newBouncing); newBouncing.x = ball.x; newBouncing.y = ball.y; counter--; } stop();

14 Controlling Movement What if we want to have a bat which the user controls and can use to bounce balls back up the screen? Well the first thing to do is to fix things so that when a ball falls off the bottom of the screen it doesn’t bounce back up.

15 Controlling Movement We already have a segment of code which detects if the ball hits the bottom (this is attached to the second frame of the bouncing symbol). This just reverses its direction. We want to take it out of the game. So replace it with the following code... else if(this.y>400) { ymove = 0 - ymove; this.y=400; }

16 Controlling Movement Now the next step might be to make a bat. This will simply be a movie symbol which will follow the mouse horizontally across the stage. (We have done one of these already). else if (this.y>400){ this.y=450; stop(); }

17 Controlling Movement Do this by creating a graphic symbol (called e.g. bat) then creating a new movie clip symbol (called e.g. movingBat), dragging an instance of bat onto the movie clip stage (positioning at 0,0). Then click onto Scene 1 and drag an instance of the movie clip movingBat into an appropriate position. Call the instance myBat. Then add some ActionScript to move myBat...

18 Controlling Movement Attach this to the first frame of the movie clip symbol movingBat. Add a keyframe at frame 2 and put this code in it this.x = root.mouseX; gotoAndPlay(1);

19 Controlling Movement We now need to get the balls to bounce off the bat. In order to do this we are going to use the hitTestObject() method. This is a method attached to all movie clips where we can test if the movieClip has hit another movieClip. We want to get each ball to test if it has hit the bat.

20 Controlling Movement So as it stands the ball tests if it has hit the top wall, the left wall, the right wall, the bottom. We simply add another else if to test if it has hit the bat as follows: else if (this.hitTestObject(MovieClip(parent).myBat)) { ymove=0-ymove; }

21 Exercise 1. Make it so the balls speed up as the game progresses. 2. Change it so that we have four bats on each side of the screen (all controlled by the mouse position). We can only keep balls in play by hitting them with the bats.

22 Firing Bullets What if we want to have a spaceship which fires bullets up the screen? We are going to need two movieclip objects 1. A ship symbol 2. A bullet symbol We can set up the ship symbol in much the same way as the bat in the previous example i.e. it moves horizontally. In this case we will set it so that it moves horizontally using the arrow keys. Suppose we have created an instance of a movieclip symbol which contains a graphic of a ship and placed it on the stage. We create three keyframes and attach the following ActionScript to the movie clip symbol.

23 Firing Bullets Frame 1 Position of Spaceship Set Speed this.x = 235; this.y = 320; var speed:int = 10;

24 Firing Bullets Frame 2 function moveShip(event:KeyboardEvent):void { if ((event.keyCode == Keyboard.LEFT) && (this.x > 0)) { this.x -= speed; } if ((event.keyCode == Keyboard.RIGHT) && (this.x < 520)){ this.x += speed; } stage.addEventListener(KeyboardEvent.KEY_DOWN, moveShip);

25 Firing Bullets This creates a function moveShip to respond to any key being pressed. Each key has a code associated with it. This can be a constant (LEFT, RIGHT…) or a number. If we hit the left arrow key and we are still on the screen we decrease the x coordinate by some fixed amount. If we hit the right arrow key and we are still on the screen we increase the x coordinate by some fixed amount. In the third frame just place some code to jump back to the second one.

26 Firing Bullets So how do we do the bullet? Create a graphic symbol called bullet. Create a movieClip symbol called movingBullet and place bullet at (0,0). When the user presses the spacebar we position movingBullet on the screen at the ship and start it moving upwards. When the bullet has reached the top of the screen we can just position it off the screen somewhere so it is not visible.

27 Firing Bullets This is done when the user presses the spacebar. We attach this action to the ship. So the ship’s code looks like: if (user presses left key) move ship left; if (user presses right key) move ship right; if (user presses space bar) create the bullet; position the bullet on the screen;

28 Firing Bullets So we get: function moveShip(event:KeyboardEvent):void { if ((event.keyCode == Keyboard.LEFT) && (this.x > 0)) { this.x -= speed; } if ((event.keyCode == Keyboard.RIGHT) && (this.x < 520)){ this.x += speed; } if (event.keyCode == Keyboard.SPACE){ var newBullet:MovieClip = new movingBullet(); parent.addChild(newBullet); newBullet.x=this.x; newBullet.y=this.y; }

29 Firing Bullets Remember to set your Linkage Property for movingBullet to Export for Actionscript. Every time the user hits the spacebar Flash creates a new instance of movingBullet and places it on the screen at the same place as the Ship. Now we need to get the bullet moving…

30 Firing Bullets Frame 1 Frame 2 Position off the screen if it’s at < 0 this.y -= 10; if(this.y < 0) { this.y = -100; } gotoAndPlay(1); Move the bullet up 10 pixels

31 Exercises Add another movie clip/sprite to this. This sprite should be some sort of object which moves horizontally across the top of the screen, back and forth. Use the hitTestObject() method to figure out if the bullet hits it. If so get it to disappear or make a sound or jump to another frame and stop or something !