Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

flash as3 physics if statement issue :

Contributor ,
Feb 28, 2016 Feb 28, 2016

When velocity is greater than 4 , the ball should stop . i also tried the code   if(xx>4) { ball.stop(); } inside score . and outside scope . . but does not  work

// set gravity amount

var gravity:Number = .000098;

// set starting velcity

var xx:Number = 0.2;

// mark start time and add listener

var lastTime:int = getTimer();

addEventListener(Event.ENTER_FRAME, animateBall);

// step animation

function animateBall(event:Event) {

  // get time difference

  var timeDiff:int = getTimer()-lastTime;

  lastTime += timeDiff;

  // adjust vertical speed for gravity

  xx+= gravity*timeDiff;

  // move ball

  ball.rotation += timeDiff*xx;

}

  if(xx>4) {

  ball.stop();

  }

TOPICS
ActionScript
315
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 28, 2016 Feb 28, 2016

that code will stop the timeline of ball, but it won't stop ball from rotating.

if you want to stop ball from rotating when xx>4, use:

// set gravity amount

var gravity:Number = .000098;

// set starting velcity

var xx:Number = 0.2;

// mark start time and add listener

var lastTime:int = getTimer();

addEventListener(Event.ENTER_FRAME, animateBall);

// step animation

function animateBall(event:Event) {

  // get time difference

  var timeDiff:int = getTimer()-lastTime;

  lastTime += timeDiff;

...
Translate
Community Expert ,
Feb 28, 2016 Feb 28, 2016
LATEST

that code will stop the timeline of ball, but it won't stop ball from rotating.

if you want to stop ball from rotating when xx>4, use:

// set gravity amount

var gravity:Number = .000098;

// set starting velcity

var xx:Number = 0.2;

// mark start time and add listener

var lastTime:int = getTimer();

addEventListener(Event.ENTER_FRAME, animateBall);

// step animation

function animateBall(event:Event) {

  // get time difference

  var timeDiff:int = getTimer()-lastTime;

  lastTime += timeDiff;

  // adjust vertical speed for gravity

  xx+= gravity*timeDiff;

  // move ball

if(xx<=4){

  ball.rotation += timeDiff*xx;

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines