MCPcopy Index your code
hub / github.com/KilledByAPixel/LittleJS / render

Method render

plugins/medalSystem.js:173–209  ·  view source on GitHub ↗

Render a medal * @param {number} [hidePercent] - How much to slide the medal off screen

(hidePercent=0)

Source from the content-addressed store, hash-verified

171 * @param {number} [hidePercent] - How much to slide the medal off screen
172 */
173 render(hidePercent=0)
174 {
175 const context = mainContext;
176 const width = min(medalDisplaySize.x, mainCanvas.width);
177 const height = medalDisplaySize.y;
178 const x = mainCanvas.width - width;
179 const y = -height*hidePercent;
180 const backgroundColor = hsl(0,0,.9);
181
182 // draw containing rect and clip to that region
183 context.save();
184 context.beginPath();
185 context.fillStyle = backgroundColor.toString();
186 context.strokeStyle = BLACK.toString();
187 context.lineWidth = 3;
188 context.rect(x, y, width, height);
189 context.fill();
190 context.stroke();
191 context.clip();
192
193 // draw the icon
194 const gap = vec2(.1, .05).scale(height);
195 const medalDisplayIconSize = height - 2*gap.x;
196 this.renderIcon(vec2(x + gap.x + medalDisplayIconSize/2, y + height/2), medalDisplayIconSize);
197
198 // draw the name
199 const nameSize = height*.5;
200 const descriptionSize = height*.3;
201 const pos = vec2(x + medalDisplayIconSize + 2*gap.x, y + gap.y*2 + nameSize/2);
202 const textWidth = width - medalDisplayIconSize - 3*gap.x;
203 drawTextScreen(this.name, pos, nameSize, BLACK, 0, undefined, 'left', undefined, undefined, textWidth);
204
205 // draw the description
206 pos.y = y + height - gap.y*2 - descriptionSize/2;
207 drawTextScreen(this.description, pos, descriptionSize, BLACK, 0, undefined, 'left', undefined, undefined, textWidth);
208 context.restore();
209 }
210
211 /** Render the icon for a medal
212 * @param {Vector2} pos - Screen space position

Callers 1

medalsRenderFunction · 0.45

Calls 6

renderIconMethod · 0.95
hslFunction · 0.85
vec2Function · 0.85
drawTextScreenFunction · 0.85
toStringMethod · 0.45
scaleMethod · 0.45

Tested by

no test coverage detected