Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

10 years ago by wingedwolf123

Ok so i m following along with a book hoping it ll sink a little bit and some of it is
but some of it still causes head aches , if one of you dont mind could you please explain this to me in dumbed down version lol( if i m understanding right X is is on the X axis and vel is Velocity ) but how does it translate into the following code
code is from resident raver init function of EntityBullet object- Thank you guys in advance
init: function( x, y, settings) {
this.parent(x + (settings.flip ? - 4 : 8), y+8, settings);
this.vel.x = this.accel.x = (settings.flip ? -this.maxVel.x : this.maxVel.x);
},

10 years ago by Joncom

Do you mean the parts that look like ( ... ? ... : ... )?
Those parts are called conditional ternary operators.
Don't worry about the name.

They work like this:
var is_true = true;
var sentence = ( is_true ? "I'm Joncom" : "I'm Obama" );

sentence will be equal to "I'm Joncom" because is_true == true.
If is_true were false then sentence would be "I'm Obama".

So it's basically a more compact way of writing:
var is_true = true;
var sentence;
if( is_true ) { 
    sentence = "I'm Joncom"; 
} else { 
    sentence = "I'm Obama"; 
}

10 years ago by wingedwolf123

Yes thankyou that clears it up a lot.. one last question lol in handleMovementTrace: function ( res) what is res referring too..

10 years ago by stahlmanDesign

Each entity has an init function where position (x, y) must be provided so the game knows where it belongs in the level map. If it's a bullet entity, the position will probably be roughly where the barrel of the gun was.

So in this case, a bullet is spawned when shot and placed at point x,y

settings is an object that can contain any additional information.

In this case it contains flip (true or false) so the bullet graphic will either face left or right depending on which direction it was shot (whichever direction the gun was facing)

10 years ago by Joncom

what is res referring too
res (short for result) is basically an object that tells you a few things about how the entity has collided with its environment. For example, if the entity collided with a wall on his right side during the frame, then res.collision.x would be true.

If you haven't already, take a look at the documentation:
http://impactjs.com/documentation/class-reference/entity#handlemovementtrace

Also, this describes res pretty well:
http://impactjs.com/documentation/class-reference/collisionmap#trace

10 years ago by wingedwolf123

Lol thankyou you've been very helpful I will definitely read it today just that little bit of info cleared up a lot of confusion
Page 1 of 1
« first « previous next › last »