
|
| Sprite Object: vector()
<div id="ship" style="position:absolute; width:50px; height:36px; overflow:hidden;">
<img src="shipani.gif"> </div>
ship=new sprite(50,36,"ship","ww");
This is used to create a sprite with a width of 50 pixels, a height of 36 pixels, which is rectangular, linked to the DIV called "ship" and which goes off any side of the screen and returns on the opposite side.To start simple, I will introduce a form which accesses the vector() method - ![]() The first of these is the power value. In this example, it would be accessed via ship.power. This value controls the acceleration of the sprite. Next is the friction value. Again, it is be accessed by ship.frict. The default value in the JavaScript file is 0.98. Be careful when modifying this value - only values above 0 and below 1 are allowed. 0 would hold the sprite solidly in place. 1 or more would boost the speed until it got out of control. Less than 0 gives strange results. Then we have the bearing value, accessed via ship.bearing. This controls the direction of the sprite. Only integer (whole number) values between 0 and 359 inclusive are valid. A few points of reference are -
The vector() method also takes into account the boundry value. You may position your sprite "manually" by changing the xPos and yPos values. By the same token, you may change the xSpd and ySpd values to control the speed of the sprite, but this can be complicated. One way to add a gravitational effect would be to add a constant negative value to ySpd (effectively pulling the sprite downwards). A constant positive value would be antigravity. A recent addition to the sprite object is the position() method. This new method is a scaled down version of the vector() method. It does not apply momentum, friction or power to an object, it simply places the sprite at the current xPos and yPos coordinates. This cuts down on processing time when you need to position lots of sprites very quickly. |