mirror of
https://github.com/Aviortheking/games.git
synced 2025-07-04 07:09:18 +00:00
@ -6,13 +6,13 @@ import Renderer from '.'
|
||||
|
||||
interface Params {
|
||||
material?: string | Asset
|
||||
stroke?: string
|
||||
stroke?: string | {color: string, width: number}
|
||||
}
|
||||
|
||||
export default class RectRenderer extends Renderer implements Params {
|
||||
|
||||
public material?: string | Asset
|
||||
public stroke?: string
|
||||
public stroke?: string | {color: string, width: number}
|
||||
|
||||
public constructor(component: Component2D, params?: Params) {
|
||||
super(component)
|
||||
@ -45,7 +45,12 @@ export default class RectRenderer extends Renderer implements Params {
|
||||
ctx.fillRect(...item)
|
||||
}
|
||||
if (this.stroke) {
|
||||
ctx.strokeStyle = this.stroke
|
||||
if (typeof this.stroke === 'string') {
|
||||
ctx.strokeStyle = this.stroke
|
||||
} else {
|
||||
ctx.strokeStyle = this.stroke.color
|
||||
ctx.lineWidth = this.stroke.width
|
||||
}
|
||||
ctx.strokeRect(...item)
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,8 @@ export default class TextRenderer extends Renderer {
|
||||
|
||||
public text?: string
|
||||
public size?: number
|
||||
public weight?: 'bold'
|
||||
public color?: string
|
||||
|
||||
public constructor(component: Component2D, params?: Params) {
|
||||
super(component)
|
||||
@ -31,10 +33,11 @@ export default class TextRenderer extends Renderer {
|
||||
|
||||
// console.log
|
||||
if (this.text) {
|
||||
ctx.fillStyle = 'black'
|
||||
ctx.textBaseline = 'top'
|
||||
ctx.fillStyle = this.color ?? 'black'
|
||||
ctx.textBaseline = 'middle'
|
||||
ctx.textAlign = 'center'
|
||||
|
||||
ctx.font = `${size}px sans-serif`
|
||||
ctx.font = `${this.weight ? `${this.weight} ` : ''}${size + (this.size ?? 0)}px sans-serif`
|
||||
ctx.fillText(this.text, ...item)
|
||||
}
|
||||
}
|
||||
|
@ -10,7 +10,11 @@ export default abstract class Renderer {
|
||||
|
||||
protected getPosition(): Vector2D {
|
||||
const ge = GameEngine.getGameEngine()
|
||||
const realPosition = ge.currentScene!.camera.topLeft.sum(this.component.position)
|
||||
const realPosition = ge.currentScene?.camera.topLeft.sum(this.component.position)
|
||||
if (!realPosition) {
|
||||
console.error('no camera?!?')
|
||||
return this.component.position
|
||||
}
|
||||
return new Vector2D(
|
||||
realPosition.x - this.component.scale.x / 2 - this.component.origin.x,
|
||||
realPosition.y - this.component.scale.y / 2 - this.component.origin.y
|
||||
|
Reference in New Issue
Block a user