cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Did you get called away in the middle of writing a post? Don't worry you can find your unfinished post later in the Drafts section of your profile page. X

Moving multiple models

micah
12-Amethyst

Moving multiple models

I'm using the code below to move multiple models. The issue I'm having is they all have different starting locations. So they appear to 'jump' to that Y coordinate, and then move up. Is there a way to have the function inherit the original value and then move up?

 

$scope.posChange1 = function() {
$scope.app.params['ClipMovement']+=0.0001;
}

$scope.moveClip = function() {
$scope.app.params['ClipMovement'] = 1.329;
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};

1 ACCEPTED SOLUTION

Accepted Solutions
micah
12-Amethyst
(To:sebben)

That works perfectly. Another issue I'm having is looping the movement.

I've tried:

 

$scope.moveClip = $interval(function() {
for(var i=0; i< 3; i++){
$scope.view.wdg[Objects[i]].y=start[i];
}
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
}, 1000);

 

Where moveClip(); is bound to a click function of a button. But the loop starts when the view is loaded rather than when the button is clicked.

 

(Also, how do you add code to post in that box?)

View solution in original post

5 REPLIES 5
sebben
12-Amethyst
(To:micah)

Hi,

 

you can write your objects in a list and loop through it like this:

 

var Objects =["3DGauge-1","3DGauge-2","3DGauge-3"];

$scope.posChange1 = function() {
  for(var i=0; i< 3; i++){
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
  }
}

$scope.moveClip = function() {
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};
micah
12-Amethyst
(To:sebben)

This isn't suitable for my situation because if I run that function twice it will incrementally add from the last position. I'd like the models to move from each of their original positions, and if the function is run again, go back to the original and then move up.

 

Is there a way to call back the original 'y' position of all the models?

sebben
12-Amethyst
(To:micah)

You can store them in an array on startup and change the values to the original each time you call the function.

Something like this:

var Objects =["3DGauge-1","3DGauge-2","3DGauge-3"];
var start = []; 
$scope.$on("$ionicView.loaded", function (event) {
   for(var i=0; i< 3; i++){
	start.push($scope.app.view.Home.wdg[Objects[i]].y);
  }
});

$scope.posChange1 = function() {
  for(var i=0; i< 3; i++){ 
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
  }
}

$scope.moveClip = function() {
    for(var i=0; i< 3; i++){
	$scope.app.view.Home.wdg[Objects[i]].y=start[i];
  }
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
};
micah
12-Amethyst
(To:sebben)

That works perfectly. Another issue I'm having is looping the movement.

I've tried:

 

$scope.moveClip = $interval(function() {
for(var i=0; i< 3; i++){
$scope.view.wdg[Objects[i]].y=start[i];
}
$scope.intervalPromise = $interval($scope.posChange1, 10, 100);
}, 1000);

 

Where moveClip(); is bound to a click function of a button. But the loop starts when the view is loaded rather than when the button is clicked.

 

(Also, how do you add code to post in that box?)

sebben
12-Amethyst
(To:micah)

Hi,

I'm not sure why this start when the view is loaded, but you could just call the the moveClip function from the posChange1 function when it comes to the end of the interval:

 

$scope.posChange1 = function() {
  for(var i=0; i< 3; i++){ 
	$scope.app.view.Home.wdg[Objects[i]].y+=0.0001;
  }
  if($scope.app.view.Home.wdg[Objects[0]].y >= start[0]+0.0099){
  $scope.moveClip();
  }
}

To insert a code sample you have to click first the three dots to extent the toolbar ( ... ) and then click on the </> symbol.

Top Tags