SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados (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
 

Destaque

Artdm170 week12 user_interaction
Artdm170 week12 user_interactionArtdm170 week12 user_interaction
Artdm170 week12 user_interaction
Gilbert Guerrero
 
American Spy Hidden Camera watch
 American Spy Hidden Camera watch American Spy Hidden Camera watch
American Spy Hidden Camera watch
george david
 
ARTDM170 Week2: GIF Animation
ARTDM170 Week2: GIF AnimationARTDM170 Week2: GIF Animation
ARTDM170 Week2: GIF Animation
Gilbert Guerrero
 

Destaque (8)

Conf Aen
Conf AenConf Aen
Conf Aen
 
Artdm170 week12 user_interaction
Artdm170 week12 user_interactionArtdm170 week12 user_interaction
Artdm170 week12 user_interaction
 
Twitter improves your journalism
Twitter improves your journalismTwitter improves your journalism
Twitter improves your journalism
 
American Spy Hidden Camera watch
 American Spy Hidden Camera watch American Spy Hidden Camera watch
American Spy Hidden Camera watch
 
ARTDM170 Week2: GIF Animation
ARTDM170 Week2: GIF AnimationARTDM170 Week2: GIF Animation
ARTDM170 Week2: GIF Animation
 
Planning for an Uncertain Future. Jaap van der Meer, TAUS
Planning for an Uncertain Future. Jaap van der Meer, TAUSPlanning for an Uncertain Future. Jaap van der Meer, TAUS
Planning for an Uncertain Future. Jaap van der Meer, TAUS
 
Manage your changing workload
Manage your changing workloadManage your changing workload
Manage your changing workload
 
Planning Digital Enterprise Stories
Planning Digital Enterprise StoriesPlanning Digital Enterprise Stories
Planning Digital Enterprise Stories
 

Semelhante a Artdm170 Week6 Scripting Motion

Artdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To FlashArtdm170 Week5 Intro To Flash
Artdm170 Week5 Intro To Flash
Gilbert 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 Flash
Gilbert Guerrero
 
ARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting InteractivityARTDM 170 Week 8: Scripting Interactivity
ARTDM 170 Week 8: Scripting Interactivity
Gilbert Guerrero
 
Im flash
Im flashIm flash
Im flash
huanwu
 
14multithreaded Graphics
14multithreaded Graphics14multithreaded Graphics
14multithreaded Graphics
Adil Jafri
 
Artdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script EffectsArtdm170 Week4 Java Script Effects
Artdm170 Week4 Java Script Effects
Gilbert Guerrero
 

Semelhante a 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
 

Mais de Gilbert 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 QA
Gilbert Guerrero
 
Artdm 170 week15 publishing
Artdm 170 week15 publishingArtdm 170 week15 publishing
Artdm 170 week15 publishing
Gilbert 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 Processing
Gilbert Guerrero
 
ARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation SchemesARTDM 171, Week 13: Navigation Schemes
ARTDM 171, Week 13: Navigation Schemes
Gilbert Guerrero
 
Artdm 171 Week12 Templates
Artdm 171 Week12 TemplatesArtdm 171 Week12 Templates
Artdm 171 Week12 Templates
Gilbert 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 Comps
Gilbert 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 Prototypes
Gilbert Guerrero
 
ARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User Experience
Gilbert Guerrero
 
ARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping CyberspaceARTDM 171, Week 7: Remapping Cyberspace
ARTDM 171, Week 7: Remapping Cyberspace
Gilbert Guerrero
 
ARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting InteractivityARTDM 170, Week 7: Scripting Interactivity
ARTDM 170, Week 7: Scripting Interactivity
Gilbert Guerrero
 
Artdm170 week6 scripting_motion
Artdm170 week6 scripting_motionArtdm170 week6 scripting_motion
Artdm170 week6 scripting_motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 
Artdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting MotionArtdm170 Week6 Scripting Motion
Artdm170 Week6 Scripting Motion
Gilbert Guerrero
 

Mais de Gilbert Guerrero (20)

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 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 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 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 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 171, Week 9: User Experience
ARTDM 171, Week 9: User ExperienceARTDM 171, Week 9: User Experience
ARTDM 171, Week 9: User Experience
 
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
 
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
 
Artdm171 Week4 Tags
Artdm171 Week4 TagsArtdm171 Week4 Tags
Artdm171 Week4 Tags
 

Último

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
ciinovamais
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17How to Create and Manage Wizard in Odoo 17
How to Create and Manage Wizard in Odoo 17
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Application orientated numerical on hev.ppt
Application orientated numerical on hev.pptApplication orientated numerical on hev.ppt
Application orientated numerical on hev.ppt
 
Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Magic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptxMagic bus Group work1and 2 (Team 3).pptx
Magic bus Group work1and 2 (Team 3).pptx
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...Kodo Millet  PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
Kodo Millet PPT made by Ghanshyam bairwa college of Agriculture kumher bhara...
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
ICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptxICT Role in 21st Century Education & its Challenges.pptx
ICT Role in 21st Century Education & its Challenges.pptx
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 

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

Notas do Editor