Help with ImpactJS Update( )

Need help with an engine or coding not on the list? Need help with a game or the website and forums here? Direct all questions here.
Post Reply
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Help with ImpactJS Update( )

Post 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).
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Help with ImpactJS Update( )

Post by MikeD »

Here's a visual of what I mean.

Image
User avatar
Ark
Posts: 427
Joined: Wed Jun 01, 2011 10:25 pm

Re: Help with ImpactJS Update( )

Post 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).
Orgullo Catracho
User avatar
MikeD
Posts: 294
Joined: Thu Sep 08, 2011 4:28 am

Re: Help with ImpactJS Update( )

Post 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
Post Reply

Return to “Advanced Help and Support”