SlideShare une entreprise Scribd logo
1  sur  25
ARTDM 170, Week 6: Using
 Objects + Scripting Motion
          Gilbert Guerrero
         gguerrero@dvc.edu
 gilbertguerrero.com/blog/artdm-170
Adobe Flash
Open Flash and create a new
 ActionScript 3.0 document...
Create an ActionScript class

• Save your ActionScript file, example:
  MyAnimation.fla
• Go to New... > ActionScript File   to
  create a new external AS file
• Save the file using the same name as
  your Flash file, example:

  MyAnimation.as
Review: ActionScript Class
                Class file declaration
package {                  Library classes needed
  import flash.display.*;
  import flash.text.*;                Class definition
    public class HelloWorld2 extends MovieClip {


        public function HelloWorld2() {
          var myText: TextField = new TextField();
          myText.text = "Hello World!";
          addChild(myText);
        }
    }                                   Constructor
}
Create a new AS class
 package {
   import flash.display.*;

     public class MyAnimation extends Sprite {


         public function MyAnimation() {

         }
     }
 }
Placing objects on the stage

• Programmatically (using Flash
  display objects)
• Library (named instances)
• Library + Programmatically (export
  for ActionScript)
Drawing a circle with code

• Add this code to your class to draw a
  circle on the screen
public var myCircle:Sprite = new Sprite();
myCircle.graphics.lineStyle(5,0x000000);
myCircle.graphics.beginFill(0xCCCCCC);
myCircle.graphics.drawCircle(0,0,25);
addChild(myCircle);
Draw a circle
•   Create a new movie clip
•   Draw a circle
•   Drag it onto the stage
•   Name the instance of the object
•   The instance name becomes the way to use
    the object in the code:
    //moves circle to the upper corner
    happyFunBall.x = 0;
    happyFunBall.y = 0;
Export for ActionScript

• Open the Properties for an object in
  the library
• Check export for ActionScript and
  click OK
• Flash will create a class for you
Export for ActionScript

• Now you can created an unlimited
 number of named instances in the
 code to add the object to the stage
var superFunBall:Ball = new Ball();
superFunBall.x = 0;
superFunBall.y = 0;
addChild(superFunBall);
Computer Animation
Moving objects

• An instance of a movie clip can be
 moved to any location using x and y
 as coordinates:
myCircle.x = 300;
myCircle.y = 200;
Updating location
• By updating x and y values we can change
 the location of our object


// Move the clips
 myCircle.x = myCircle.x + 10;
 myCircle.y = myCircle.y + 10;
Traditional Animation



  frame   frame   frame
     1       2       3
Computer Animation



 render       display    render       display
frame 1      frame 1    frame 2      frame 2




     Executes code          Executes code
(Dynamic) Flash Animation

                   There’s only one frame!


 get                                  apply
          render       display
initial                              rules to
           frame       frame
state                                 state
Event Listeners
•   By using an event listener that's triggered by
    ENTER_FRAME the movie clip instance will move on
    it's own
addEventListener(Event.ENTER_FRAME,
myFunction);
Movement function
public function onMoveCircle
  (e:Event):void {
    myCircle.x = myCircle.x + moveX;
    myCircle.y = myCircle.y + moveY;

}
Triggering movement
package {
	    import flash.display.*;
	    import flash.events.*;
	
	    public class MyAnimation extends MovieClip {
	    	
	    	    // Setup the values
	    	    private var myCircle:Sprite;
	    	
	    	    public function MyAnimation() {
	    	    	    myCircle = new Sprite();
	    	    	    myCircle.graphics.beginFill(0xCCCCCC);
	    	    	    myCircle.graphics.drawCircle(0,0,25);
	    	    	    addChild(theBall);
	    	    	    addEventListener(Event.ENTER_FRAME,
onMoveCircle);
	    	    }
	    	    public function onMoveCircle(pEvent:Event):void {
	    	        myCircle.x = myCircle.x + 10;
                myCircle.y = myCircle.y + 10;
	    	    }
	    }
}
Bounce the clip off the edges
•   The edge of the stage can be detected by
    determining if the movie clip's x or y values are
    greater or less than the stage width or height:
    myClip.x > stage.stageWidth 
    myClip.x < 0 
    myClip.y > stage.stageHeight

    myClip.y < 0  

•   stage.stageWidth and stage.stageHeight are
    variables stored by Flash that you can access at
    any time.
Change direction
•   The direction of the clip can be changed when an
    edge is detected:
if(myClip.x > stage.stageWidth || myClip.x < 0) {

        moveX = -moveX; 
    }  
if(myClip.y > stage.stageHeight || myClip.y < 0) {

        moveY = -moveY; 

    }  
Bounce the clip off the edges
// Setup the values
var moveX:Number = 10;
var moveY:Number = 10;
function moveClip(pEvent:Event):void {
    if(myClip.x > stage.stageWidth ||  myClip.x < 0){
        moveX = -moveX;  //change direction
    }    
    if(myClip.y > stage.stageHeight ||  myClip.y < 0){
        moveY = -moveY;  //change direction
    }    
    // Move the clips 
    myClip.x = myClip.x + moveX;
    myClip.y = myClip.y + moveY;
}
// Trigger the movement automatically
addEventListener(Event.ENTER_FRAME, moveClip);
Use the edge of the ball
For a more realistic bounce the edge of the ball should
be detected when it comes into contact with the edge. 
Do this by adding or subtracting half the width of the
ball:
myClip.width/2
myClip.height/2

The full statements:
myClip.x > stage.stageWidth - myClip.width/2 ||
myClip.x < myClip.width/2
myClip.y > stage.stageHeight - myClip.height/2 ||
myClip.y < myClip.height/2
Bounce using the ball edges
var moveX:Number = 10;
var moveY:Number = 10;

function moveClip(pEvent:Event):void {
    if(myClip.x > stage.stageWidth - myClip.width/2
||  myClip.x < myClip.width/2){
        moveX = -moveX;  //change direction
    }    
    if(myClip.y > stage.stageHeight - myClip.height/2
||  myClip.y < myClip.height/2){
        moveY = -moveY;  //change direction
    }   
    myClip.x = myClip.x + moveX;
    myClip.y = myClip.y + moveY;
}
Homework, due March 9

• Read p65-81, Chapter 2:
  ActionScript Game Elements in AS
  3.0 Game Programming University
• Create a Flash movie with scripted
  motion
 • Add an object to the stage
 • Make the object move across the
   screen using ActionScript

Contenu connexe

Tendances

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10Vanishree Arun
 
Introducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilderIntroducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilderEduardo Lundgren
 
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012Eduardo Lundgren
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysGilbert Guerrero
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricksdeanhudson
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8Vanishree Arun
 
La 4 grafik komputer
La 4 grafik komputerLa 4 grafik komputer
La 4 grafik komputerYudo Rahadya
 

Tendances (8)

10CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 1010CSL67 CG LAB PROGRAM 10
10CSL67 CG LAB PROGRAM 10
 
Rxjs kyivjs 2015
Rxjs kyivjs 2015Rxjs kyivjs 2015
Rxjs kyivjs 2015
 
Introducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilderIntroducing AlloyUI DiagramBuilder
Introducing AlloyUI DiagramBuilder
 
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
YUI3 and AlloyUI Introduction for Pernambuco.JS 2012
 
ARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + ArraysARTDM 170, Week 13: Text Elements + Arrays
ARTDM 170, Week 13: Text Elements + Arrays
 
Stupid Canvas Tricks
Stupid Canvas TricksStupid Canvas Tricks
Stupid Canvas Tricks
 
10CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 810CSL67 CG LAB PROGRAM 8
10CSL67 CG LAB PROGRAM 8
 
La 4 grafik komputer
La 4 grafik komputerLa 4 grafik komputer
La 4 grafik komputer
 

En vedette

ARTDM 170 Week 1: Introduction
ARTDM 170 Week 1: IntroductionARTDM 170 Week 1: Introduction
ARTDM 170 Week 1: IntroductionGilbert Guerrero
 
Artdm171 Week2: History of the Web
Artdm171 Week2: History of the WebArtdm171 Week2: History of the Web
Artdm171 Week2: History of the WebGilbert Guerrero
 
ARTDM 170, Week 11: User Interaction
ARTDM 170, Week 11: User InteractionARTDM 170, Week 11: User Interaction
ARTDM 170, Week 11: User InteractionGilbert Guerrero
 
ARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceGilbert Guerrero
 
ARTDM 170, Week 16: Publishing
ARTDM 170, Week 16: PublishingARTDM 170, Week 16: Publishing
ARTDM 170, Week 16: PublishingGilbert Guerrero
 
ARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page CompsARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page CompsGilbert Guerrero
 
ARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: RolloversARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: RolloversGilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionGilbert Guerrero
 
ARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper PrototypesARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper PrototypesGilbert Guerrero
 
ARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversGilbert Guerrero
 
Artdm170 week12 user_interaction
Artdm170 week12 user_interactionArtdm170 week12 user_interaction
Artdm170 week12 user_interactionGilbert Guerrero
 
ARTDM 170, Week 15: Advanced
ARTDM 170, Week 15: AdvancedARTDM 170, Week 15: Advanced
ARTDM 170, Week 15: AdvancedGilbert Guerrero
 
ARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to ProcessingARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to ProcessingGilbert Guerrero
 
ARTDM 170, Week 2: GIF Animation
ARTDM 170, Week 2: GIF AnimationARTDM 170, Week 2: GIF Animation
ARTDM 170, Week 2: GIF AnimationGilbert Guerrero
 

En vedette (18)

ARTDM 170 Week 1: Introduction
ARTDM 170 Week 1: IntroductionARTDM 170 Week 1: Introduction
ARTDM 170 Week 1: Introduction
 
Artdm171 Week2: History of the Web
Artdm171 Week2: History of the WebArtdm171 Week2: History of the Web
Artdm171 Week2: History of the Web
 
ARTDM 170, Week 11: User Interaction
ARTDM 170, Week 11: User InteractionARTDM 170, Week 11: User Interaction
ARTDM 170, Week 11: User Interaction
 
ARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User Experience
 
ARTDM 170, Week 16: Publishing
ARTDM 170, Week 16: PublishingARTDM 170, Week 16: Publishing
ARTDM 170, Week 16: Publishing
 
ARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page CompsARTDM 171, Week 10: Mood Boards + Page Comps
ARTDM 171, Week 10: Mood Boards + Page Comps
 
ARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: RolloversARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: Rollovers
 
ARTDM 171 Week 4: Tags
ARTDM 171 Week 4: TagsARTDM 171 Week 4: Tags
ARTDM 171 Week 4: Tags
 
Artdm171 Week12 Hosting
Artdm171 Week12 HostingArtdm171 Week12 Hosting
Artdm171 Week12 Hosting
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm171 Week5 Css
Artdm171 Week5 CssArtdm171 Week5 Css
Artdm171 Week5 Css
 
ARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper PrototypesARTDM 170, Week 10: Encapsulation + Paper Prototypes
ARTDM 170, Week 10: Encapsulation + Paper Prototypes
 
ARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: RolloversARTDM 170 Week 3: Rollovers
ARTDM 170 Week 3: Rollovers
 
Artdm170 week12 user_interaction
Artdm170 week12 user_interactionArtdm170 week12 user_interaction
Artdm170 week12 user_interaction
 
ARTDM 170, Week 15: Advanced
ARTDM 170, Week 15: AdvancedARTDM 170, Week 15: Advanced
ARTDM 170, Week 15: Advanced
 
Artdm171 Week4 Tags
Artdm171 Week4 TagsArtdm171 Week4 Tags
Artdm171 Week4 Tags
 
ARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to ProcessingARTDM 170, Week 14: Introduction to Processing
ARTDM 170, Week 14: Introduction to Processing
 
ARTDM 170, Week 2: GIF Animation
ARTDM 170, Week 2: GIF AnimationARTDM 170, Week 2: GIF Animation
ARTDM 170, Week 2: GIF Animation
 

Similaire à Artdm170 Week6 Scripting Motion

Artdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashArtdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashGilbert Guerrero
 
ARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To FlashARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To FlashGilbert Guerrero
 
ARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityGilbert Guerrero
 
Im flash
Im flashIm flash
Im flashhuanwu
 
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)Korhan Bircan
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!Phil Reither
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .netStephen Lorello
 
Leaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLLeaving Flatland: getting started with WebGL
Leaving Flatland: getting started with WebGLgerbille
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded GraphicsAdil Jafri
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Gameslivedoor
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsNaman Dwivedi
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...DroidConTLV
 
Oculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion TutorialOculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion TutorialChris Zaharia
 
Coding Flash : ActionScript(3.0) Tutorial
Coding Flash :  ActionScript(3.0) TutorialCoding Flash :  ActionScript(3.0) Tutorial
Coding Flash : ActionScript(3.0) TutorialPEI-YAO HUNG
 
Stop running from animations droidcon London
Stop running from animations droidcon LondonStop running from animations droidcon London
Stop running from animations droidcon Londonmaric_iv
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsGilbert Guerrero
 

Similaire à Artdm170 Week6 Scripting Motion (20)

Artdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashArtdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To Flash
 
ARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To FlashARTDM 170, Week 5: Intro To Flash
ARTDM 170, Week 5: Intro To Flash
 
ARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting Interactivity
 
Intro to HTML5
Intro to HTML5Intro to HTML5
Intro to HTML5
 
Im flash
Im flashIm flash
Im flash
 
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)
 
HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!HTML5 Canvas - Let's Draw!
HTML5 Canvas - Let's Draw!
 
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
 
Shootting Game
Shootting GameShootting Game
Shootting Game
 
Prototype UI
Prototype UIPrototype UI
Prototype UI
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
 
HTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web GamesHTML5 Animation in Mobile Web Games
HTML5 Animation in Mobile Web Games
 
Enhancing UI/UX using Java animations
Enhancing UI/UX using Java animationsEnhancing UI/UX using Java animations
Enhancing UI/UX using Java animations
 
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
Tricks to Making a Realtime SurfaceView Actually Perform in Realtime - Maarte...
 
Oculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion TutorialOculus Rift DK2 + Leap Motion Tutorial
Oculus Rift DK2 + Leap Motion Tutorial
 
Coding Flash : ActionScript(3.0) Tutorial
Coding Flash :  ActionScript(3.0) TutorialCoding Flash :  ActionScript(3.0) Tutorial
Coding Flash : ActionScript(3.0) Tutorial
 
Stop running from animations droidcon London
Stop running from animations droidcon LondonStop running from animations droidcon London
Stop running from animations droidcon London
 
Sbaw091117
Sbaw091117Sbaw091117
Sbaw091117
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script Effects
 

Plus de Gilbert Guerrero

Designing for Skepticism and Bright Sunlight
Designing for Skepticism and Bright SunlightDesigning for Skepticism and Bright Sunlight
Designing for Skepticism and Bright SunlightGilbert Guerrero
 
ARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QAARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QAGilbert Guerrero
 
Artdm 170 week15 publishing
Artdm 170 week15 publishingArtdm 170 week15 publishing
Artdm 170 week15 publishingGilbert Guerrero
 
ARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesGilbert Guerrero
 
Artdm 171 Week12 Templates
Artdm 171 Week12 TemplatesArtdm 171 Week12 Templates
Artdm 171 Week12 TemplatesGilbert Guerrero
 
ARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceGilbert Guerrero
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityGilbert Guerrero
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motionGilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionGilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionGilbert Guerrero
 
ARTDM 171, Week 3: Web Basics + Group Projects
ARTDM 171, Week 3: Web Basics + Group ProjectsARTDM 171, Week 3: Web Basics + Group Projects
ARTDM 171, Week 3: Web Basics + Group ProjectsGilbert Guerrero
 
ARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: RolloversARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: RolloversGilbert Guerrero
 
ARTDM 171, Week 2: A Brief History + Web Basics
ARTDM 171, Week 2: A Brief History + Web BasicsARTDM 171, Week 2: A Brief History + Web Basics
ARTDM 171, Week 2: A Brief History + Web BasicsGilbert Guerrero
 
ARTDM 170, Week 1: Introduction
ARTDM 170, Week 1: IntroductionARTDM 170, Week 1: Introduction
ARTDM 170, Week 1: IntroductionGilbert Guerrero
 

Plus de Gilbert Guerrero (17)

Designing for Skepticism and Bright Sunlight
Designing for Skepticism and Bright SunlightDesigning for Skepticism and Bright Sunlight
Designing for Skepticism and Bright Sunlight
 
ARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QAARTDM 171, Week 17: Usability Testing and QA
ARTDM 171, Week 17: Usability Testing and QA
 
Artdm 171 week15 seo
Artdm 171 week15 seoArtdm 171 week15 seo
Artdm 171 week15 seo
 
Artdm 170 week15 publishing
Artdm 170 week15 publishingArtdm 170 week15 publishing
Artdm 170 week15 publishing
 
ARTDM 171, Week 14: Forms
ARTDM 171, Week 14: FormsARTDM 171, Week 14: Forms
ARTDM 171, Week 14: Forms
 
ARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation Schemes
 
Artdm 171 Week12 Templates
Artdm 171 Week12 TemplatesArtdm 171 Week12 Templates
Artdm 171 Week12 Templates
 
ARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping Cyberspace
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting Interactivity
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
 
Artdm171 Week6 Images
Artdm171 Week6 ImagesArtdm171 Week6 Images
Artdm171 Week6 Images
 
ARTDM 171, Week 3: Web Basics + Group Projects
ARTDM 171, Week 3: Web Basics + Group ProjectsARTDM 171, Week 3: Web Basics + Group Projects
ARTDM 171, Week 3: Web Basics + Group Projects
 
ARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: RolloversARTDM 170, Week 3: Rollovers
ARTDM 170, Week 3: Rollovers
 
ARTDM 171, Week 2: A Brief History + Web Basics
ARTDM 171, Week 2: A Brief History + Web BasicsARTDM 171, Week 2: A Brief History + Web Basics
ARTDM 171, Week 2: A Brief History + Web Basics
 
ARTDM 170, Week 1: Introduction
ARTDM 170, Week 1: IntroductionARTDM 170, Week 1: Introduction
ARTDM 170, Week 1: Introduction
 

Dernier

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)lakshayb543
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmStan Meyer
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDhatriParmar
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...Nguyen Thanh Tu Collection
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationdeepaannamalai16
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvRicaMaeCastro1
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Seán Kennedy
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1GloryAnnCastre1
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptxmary850239
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxSayali Powar
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfPatidar M
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4JOYLYNSAMANIEGO
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseCeline George
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfPrerana Jadhav
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSMae Pangan
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptxmary850239
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research DiscourseAnita GoswamiGiri
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxMichelleTuguinay1
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Developmentchesterberbo7
 

Dernier (20)

Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
Visit to a blind student's school🧑‍🦯🧑‍🦯(community medicine)
 
Oppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and FilmOppenheimer Film Discussion for Philosophy and Film
Oppenheimer Film Discussion for Philosophy and Film
 
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptxDecoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
Decoding the Tweet _ Practical Criticism in the Age of Hashtag.pptx
 
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
31 ĐỀ THI THỬ VÀO LỚP 10 - TIẾNG ANH - FORM MỚI 2025 - 40 CÂU HỎI - BÙI VĂN V...
 
Congestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentationCongestive Cardiac Failure..presentation
Congestive Cardiac Failure..presentation
 
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnvESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
ESP 4-EDITED.pdfmmcncncncmcmmnmnmncnmncmnnjvnnv
 
Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...Student Profile Sample - We help schools to connect the data they have, with ...
Student Profile Sample - We help schools to connect the data they have, with ...
 
Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1Reading and Writing Skills 11 quarter 4 melc 1
Reading and Writing Skills 11 quarter 4 melc 1
 
4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx4.16.24 21st Century Movements for Black Lives.pptx
4.16.24 21st Century Movements for Black Lives.pptx
 
Paradigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTAParadigm shift in nursing research by RS MEHTA
Paradigm shift in nursing research by RS MEHTA
 
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptxBIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
BIOCHEMISTRY-CARBOHYDRATE METABOLISM CHAPTER 2.pptx
 
Active Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdfActive Learning Strategies (in short ALS).pdf
Active Learning Strategies (in short ALS).pdf
 
Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4Daily Lesson Plan in Mathematics Quarter 4
Daily Lesson Plan in Mathematics Quarter 4
 
How to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 DatabaseHow to Make a Duplicate of Your Odoo 17 Database
How to Make a Duplicate of Your Odoo 17 Database
 
Narcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdfNarcotic and Non Narcotic Analgesic..pdf
Narcotic and Non Narcotic Analgesic..pdf
 
Textual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHSTextual Evidence in Reading and Writing of SHS
Textual Evidence in Reading and Writing of SHS
 
4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx4.16.24 Poverty and Precarity--Desmond.pptx
4.16.24 Poverty and Precarity--Desmond.pptx
 
Scientific Writing :Research Discourse
Scientific  Writing :Research  DiscourseScientific  Writing :Research  Discourse
Scientific Writing :Research Discourse
 
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptxDIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
DIFFERENT BASKETRY IN THE PHILIPPINES PPT.pptx
 
Using Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea DevelopmentUsing Grammatical Signals Suitable to Patterns of Idea Development
Using Grammatical Signals Suitable to Patterns of Idea Development
 

Artdm170 Week6 Scripting Motion

  • 1. ARTDM 170, Week 6: Using Objects + Scripting Motion Gilbert Guerrero gguerrero@dvc.edu gilbertguerrero.com/blog/artdm-170
  • 2. Adobe Flash Open Flash and create a new ActionScript 3.0 document...
  • 3. Create an ActionScript class • Save your ActionScript file, example: MyAnimation.fla • Go to New... > ActionScript File to create a new external AS file • Save the file using the same name as your Flash file, example: MyAnimation.as
  • 4. Review: ActionScript Class Class file declaration package { Library classes needed import flash.display.*; import flash.text.*; Class definition public class HelloWorld2 extends MovieClip { public function HelloWorld2() { var myText: TextField = new TextField(); myText.text = "Hello World!"; addChild(myText); } } Constructor }
  • 5. Create a new AS class package { import flash.display.*; public class MyAnimation extends Sprite { public function MyAnimation() { } } }
  • 6. Placing objects on the stage • Programmatically (using Flash display objects) • Library (named instances) • Library + Programmatically (export for ActionScript)
  • 7. Drawing a circle with code • Add this code to your class to draw a circle on the screen public var myCircle:Sprite = new Sprite(); myCircle.graphics.lineStyle(5,0x000000); myCircle.graphics.beginFill(0xCCCCCC); myCircle.graphics.drawCircle(0,0,25); addChild(myCircle);
  • 8. Draw a circle • Create a new movie clip • Draw a circle • Drag it onto the stage • Name the instance of the object • The instance name becomes the way to use the object in the code: //moves circle to the upper corner happyFunBall.x = 0; happyFunBall.y = 0;
  • 9. Export for ActionScript • Open the Properties for an object in the library • Check export for ActionScript and click OK • Flash will create a class for you
  • 10. Export for ActionScript • Now you can created an unlimited number of named instances in the code to add the object to the stage var superFunBall:Ball = new Ball(); superFunBall.x = 0; superFunBall.y = 0; addChild(superFunBall);
  • 12. Moving objects • An instance of a movie clip can be moved to any location using x and y as coordinates: myCircle.x = 300; myCircle.y = 200;
  • 13. Updating location • By updating x and y values we can change the location of our object // Move the clips myCircle.x = myCircle.x + 10; myCircle.y = myCircle.y + 10;
  • 14. Traditional Animation frame frame frame 1 2 3
  • 15. Computer Animation render display render display frame 1 frame 1 frame 2 frame 2 Executes code Executes code
  • 16. (Dynamic) Flash Animation There’s only one frame! get apply render display initial rules to frame frame state state
  • 17. Event Listeners • By using an event listener that's triggered by ENTER_FRAME the movie clip instance will move on it's own addEventListener(Event.ENTER_FRAME, myFunction);
  • 18. Movement function public function onMoveCircle (e:Event):void { myCircle.x = myCircle.x + moveX; myCircle.y = myCircle.y + moveY; }
  • 19. Triggering movement package { import flash.display.*; import flash.events.*; public class MyAnimation extends MovieClip { // Setup the values private var myCircle:Sprite; public function MyAnimation() { myCircle = new Sprite(); myCircle.graphics.beginFill(0xCCCCCC); myCircle.graphics.drawCircle(0,0,25); addChild(theBall); addEventListener(Event.ENTER_FRAME, onMoveCircle); } public function onMoveCircle(pEvent:Event):void {     myCircle.x = myCircle.x + 10; myCircle.y = myCircle.y + 10; } } }
  • 20. Bounce the clip off the edges • The edge of the stage can be detected by determining if the movie clip's x or y values are greater or less than the stage width or height: myClip.x > stage.stageWidth  myClip.x < 0  myClip.y > stage.stageHeight myClip.y < 0   • stage.stageWidth and stage.stageHeight are variables stored by Flash that you can access at any time.
  • 21. Change direction • The direction of the clip can be changed when an edge is detected: if(myClip.x > stage.stageWidth || myClip.x < 0) {         moveX = -moveX;      }   if(myClip.y > stage.stageHeight || myClip.y < 0) {         moveY = -moveY;      }  
  • 22. Bounce the clip off the edges // Setup the values var moveX:Number = 10; var moveY:Number = 10; function moveClip(pEvent:Event):void {     if(myClip.x > stage.stageWidth ||  myClip.x < 0){         moveX = -moveX;  //change direction     }         if(myClip.y > stage.stageHeight ||  myClip.y < 0){         moveY = -moveY;  //change direction     }         // Move the clips      myClip.x = myClip.x + moveX;     myClip.y = myClip.y + moveY; } // Trigger the movement automatically addEventListener(Event.ENTER_FRAME, moveClip);
  • 23. Use the edge of the ball For a more realistic bounce the edge of the ball should be detected when it comes into contact with the edge.  Do this by adding or subtracting half the width of the ball: myClip.width/2 myClip.height/2 The full statements: myClip.x > stage.stageWidth - myClip.width/2 || myClip.x < myClip.width/2 myClip.y > stage.stageHeight - myClip.height/2 || myClip.y < myClip.height/2
  • 24. Bounce using the ball edges var moveX:Number = 10; var moveY:Number = 10; function moveClip(pEvent:Event):void {     if(myClip.x > stage.stageWidth - myClip.width/2 ||  myClip.x < myClip.width/2){         moveX = -moveX;  //change direction     }         if(myClip.y > stage.stageHeight - myClip.height/2 ||  myClip.y < myClip.height/2){         moveY = -moveY;  //change direction     }        myClip.x = myClip.x + moveX;     myClip.y = myClip.y + moveY; }
  • 25. Homework, due March 9 • Read p65-81, Chapter 2: ActionScript Game Elements in AS 3.0 Game Programming University • Create a Flash movie with scripted motion • Add an object to the stage • Make the object move across the screen using ActionScript

Notes de l'éditeur