Page 1 of 1

Help with ImpactJS Update( )

Posted: Fri Apr 06, 2012 7:20 pm
by MikeD
Alright well I'm trying to put together pitching in my Sim game.

I'm having a problem with the update ( ) running this pitch function over and over, so the ball goes all over the place during the pitch.

Here's my pitch function

Code: Select all

pitch: function(  ){
                var pitchType = this.randomFromTo(1,10);
                var accel = this.accelGround;
                    for (i=1;i<=2;i++){
                        if (pitchType <= 5){
                            while (this.accel.y <= 0){
                                var curveLeft = Math.random()*600;
                                this.accel.y = accel;
                                this.accel.x = -curveLeft;
                                this.flip = false;
                            }

                            this.messageBox = this.messageBox + "Curve Left \n";



                        }else if (pitchType > 5){
                            while (this.accel.y <= 0){
                                var curve = Math.random()*600;
                                this.accel.y = accel;
                                this.accel.x = curve;
                                this.flip = false;
                            }
                            this.messageBox = this.messageBox + "Curve Right \n";
                        }
                    }
            },
Here's the update function

Code: Select all

update: function() {

                this.pitch();

                this.parent();
            },
I'd like to get it to where it Runs one time until the pitch is done (At this point is when it has a collision with the catcher or wall).

Re: Help with ImpactJS Update( )

Posted: Fri Apr 06, 2012 7:22 pm
by MikeD
Here's a visual of what I mean.

Image

Re: Help with ImpactJS Update( )

Posted: Sat Apr 07, 2012 3:54 am
by Ark
Well the update function is supposed to run over n over again, if you want your function to run when the collision happens use the handleMovementTrace function.

something like:

Code: Select all

handleMovementTrace:function(res){
	this.parent(res);
	if(res.collision.x || res.collision.y){
            this.pitch();
	}
}
note that this is just when the ball touches the collision tiles not the entities(use other functions for the entities).

Re: Help with ImpactJS Update( )

Posted: Sat Apr 07, 2012 2:39 pm
by MikeD
Think I have it fixed, not 100% sure, ball doesn't seem to be going like a tornado anymore lol.

http://gyazo.com/398b6c3d187e2b70e806b4d542651c97