UNPKG

p5.raycaster

Version:

a simple p5js library for semi 3d rendering with ray casting

2,334 lines (516 loc) 25.6 kB
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>JSDoc: Class: Sprite</title> <script src="scripts/prettify/prettify.js"> </script> <script src="scripts/prettify/lang-css.js"> </script> <!--[if lt IE 9]> <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]--> <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css"> <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css"> </head> <body> <div id="main"> <h1 class="page-title">Class: Sprite</h1> <section> <header> <h2><span class="attribs"><span class="type-signature"></span></span>Sprite<span class="signature">(source, pos, width, height, angle<span class="signature-attributes">opt</span>, yAdjustment<span class="signature-attributes">opt</span>, animationGap<span class="signature-attributes">opt</span>, p5Inst<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h2> </header> <article> <div class="container-overview"> <h4 class="name" id="Sprite"><span class="type-signature"></span>new Sprite<span class="signature">(source, pos, width, height, angle<span class="signature-attributes">opt</span>, yAdjustment<span class="signature-attributes">opt</span>, animationGap<span class="signature-attributes">opt</span>, p5Inst<span class="signature-attributes">opt</span>)</span><span class="type-signature"></span></h4> <div class="description"> init a sprite </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th>Attributes</th> <th>Default</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>source</code></td> <td class="type"> <span class="param-type">p5.Image</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">source image for the sprite, single image is load and use for animation and rotation (if any), see readme for more info</td> </tr> <tr> <td class="name"><code>pos</code></td> <td class="type"> <span class="param-type">Vector</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last">{x, y} or a p5.Vector object</td> </tr> <tr> <td class="name"><code>width</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>height</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> </td> <td class="default"> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>angle</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 0 </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>yAdjustment</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 0 </td> <td class="description last">[-0.5, 0.5] -0.5 ~ 0.5, negative number will make the sprite appear lower and positive number will make it appear higher</td> </tr> <tr> <td class="name"><code>animationGap</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> 0 </td> <td class="description last">number of frame for before change to the next animation</td> </tr> <tr> <td class="name"><code>p5Inst</code></td> <td class="type"> <span class="param-type">p5</span> </td> <td class="attributes"> &lt;optional><br> </td> <td class="default"> null </td> <td class="description last">reference to the p5 instance if in instance mode, if not specified try to call functions blind to windows</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line13">line 13</a> </li></ul></dd> </dl> </div> <h3 class="subsection-title">Methods</h3> <h4 class="name" id="destroy"><span class="type-signature"></span>destroy<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> destroy the sprite to free resources </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line219">line 219</a> </li></ul></dd> </dl> <h4 class="name" id="drawBuffer"><span class="type-signature"></span>drawBuffer<span class="signature">()</span><span class="type-signature"></span></h4> <div class="description"> update image buffer of the sprite </div> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line211">line 211</a> </li></ul></dd> </dl> <h4 class="name" id="move"><span class="type-signature"></span>move<span class="signature">(movement)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>movement</code></td> <td class="type"> <span class="param-type">Vector</span> </td> <td class="description last">{x, y} or a p5.Vector</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line157">line 157</a> </li></ul></dd> </dl> <h4 class="name" id="rotate"><span class="type-signature"></span>rotate<span class="signature">(angle)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>angle</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line174">line 174</a> </li></ul></dd> </dl> <h4 class="name" id="rotateTo"><span class="type-signature"></span>rotateTo<span class="signature">(angle)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>angle</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line182">line 182</a> </li></ul></dd> </dl> <h4 class="name" id="scale"><span class="type-signature"></span>scale<span class="signature">(xRatio, yRatio)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>xRatio</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>yRatio</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line191">line 191</a> </li></ul></dd> </dl> <h4 class="name" id="scaleTo"><span class="type-signature"></span>scaleTo<span class="signature">(xRatio, yRatio)</span><span class="type-signature"></span></h4> <div class="description"> scale to the ratio relative to the origin size </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>xRatio</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> <tr> <td class="name"><code>yRatio</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line202">line 202</a> </li></ul></dd> </dl> <h4 class="name" id="setAnimationGap"><span class="type-signature"></span>setAnimationGap<span class="signature">(gap)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>gap</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">number of frame (main canvas) for before change to the other animation</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line59">line 59</a> </li></ul></dd> </dl> <h4 class="name" id="setAnimationGroups"><span class="type-signature"></span>setAnimationGroups<span class="signature">(grouping)</span><span class="type-signature"></span></h4> <div class="description"> advance animation control </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>grouping</code></td> <td class="type"> <span class="param-type">Array</span> </td> <td class="description last">arrays of animation frames in group, e.g. [[0,1,2,3],[4,5,6]]</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line67">line 67</a> </li></ul></dd> </dl> <h4 class="name" id="setCurrentAnimationGroup"><span class="type-signature"></span>setCurrentAnimationGroup<span class="signature">(group)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>group</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line75">line 75</a> </li></ul></dd> </dl> <h4 class="name" id="setYAdjustment"><span class="type-signature"></span>setYAdjustment<span class="signature">(ratio)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>ratio</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">0.5 ~ 0.5, negative number will make the sprite appear lower and positive number will make it appear higher</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line87">line 87</a> </li></ul></dd> </dl> <h4 class="name" id="update"><span class="type-signature"></span>update<span class="signature">(frameCount)</span><span class="type-signature"></span></h4> <div class="description"> update the animation, should have animation rate set </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>frameCount</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last">current frame count from main canvas</td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line96">line 96</a> </li></ul></dd> </dl> <h4 class="name" id="updateAnimationFrame"><span class="type-signature"></span>updateAnimationFrame<span class="signature">(newFrame)</span><span class="type-signature"></span></h4> <div class="description"> update the new frame for the animation </div> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>newFrame</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line112">line 112</a> </li></ul></dd> </dl> <h4 class="name" id="updateRotationFrame"><span class="type-signature"></span>updateRotationFrame<span class="signature">(angle)</span><span class="type-signature"></span></h4> <h5>Parameters:</h5> <table class="params"> <thead> <tr> <th>Name</th> <th>Type</th> <th class="last">Description</th> </tr> </thead> <tbody> <tr> <td class="name"><code>angle</code></td> <td class="type"> <span class="param-type">number</span> </td> <td class="description last"></td> </tr> </tbody> </table> <dl class="details"> <dt class="tag-source">Source:</dt> <dd class="tag-source"><ul class="dummy"><li> <a href="Sprite.js.html">Sprite.js</a>, <a href="Sprite.js.html#line133">line 133</a> </li></ul></dd> </dl> </article> </section> </div> <nav> <h2><a href="index.html">Home</a></h2><h3>Classes</h3><ul><li><a href="Camera.html">Camera</a></li><li><a href="KeyboardControl.html">KeyboardControl</a></li><li><a href="MouseControl.html">MouseControl</a></li><li><a href="PointerLockControl.html">PointerLockControl</a></li><li><a href="Sprite.html">Sprite</a></li><li><a href="TransparentWall.html">TransparentWall</a></li><li><a href="Util.html">Util</a></li><li><a href="World.html">World</a></li></ul><h3>Global</h3><ul><li><a href="global.html#createCamera">createCamera</a></li><li><a href="global.html#createSkyBox">createSkyBox</a></li><li><a href="global.html#createSprite">createSprite</a></li><li><a href="global.html#createTextureMap">createTextureMap</a></li><li><a href="global.html#createWorld">createWorld</a></li><li><a href="global.html#initKeyboardControl">initKeyboardControl</a></li><li><a href="global.html#initMouseControl">initMouseControl</a></li><li><a href="global.html#initPointerLockControl">initPointerLockControl</a></li></ul> </nav> <br class="clear"> <footer> Documentation generated by <a href="https://github.com/jsdoc/jsdoc">JSDoc 4.0.2</a> on Thu Feb 01 2024 12:26:09 GMT+0000 (Greenwich Mean Time) </footer> <script> prettyPrint(); </script> <script src="scripts/linenumber.js"> </script> </body> </html>