Skip to content

Commit

Permalink
add: Mana Icon to Wonder Coins
Browse files Browse the repository at this point in the history
  • Loading branch information
agustincarriso committed Jan 16, 2025
1 parent bb9b8e2 commit c21def8
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 14 deletions.
2 changes: 1 addition & 1 deletion src/coinshop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class CoinShop {

public products: ShopItem[] = []
public storeData: StoreItem[] = []
public textureFile: string = 'models/textures/resources_atlas_1024.png'
public textureFile: string = 'assets/models/textures/resources_atlas_1024.png'

public txInProgress: boolean = false

Expand Down
60 changes: 47 additions & 13 deletions src/ui/spriteplane.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Billboard, BillboardMode, engine, Material, MeshCollider, MeshRenderer, Transform } from '@dcl/sdk/ecs'
import { Billboard, BillboardMode, engine, Material, MeshRenderer, Transform } from '@dcl/sdk/ecs'
import { Quaternion, Vector3 } from '@dcl/sdk/math'

// @Component("SpritePlane")
Expand Down Expand Up @@ -32,9 +32,6 @@ export class SpritePlane {
_angles: Vector3 = Vector3.Zero(),
_isBillboard: boolean = false
) {
MeshRenderer.setPlane(this.entity, this.uvs)
MeshCollider.setPlane(this.entity)

Transform.createOrReplace(this.entity, {
position: _pos,
scale: _scale,
Expand Down Expand Up @@ -83,14 +80,8 @@ export class SpritePlane {
// log("loading " + _textureFile);

SpritePlane.cache = [_textureFile]

if (Material.getMutableOrNull(this.entity) === null) {
Material.setPbrMaterial(this.entity, {
texture: Material.Texture.Common({
src: _textureFile
}),
transparencyMode: 2,
roughness: 0.9
})
// this.material.emissiveTexture = _textureFile;
// this.material.emissiveIntensity = 0.5;
// this.material.reflectionColor = Color3.White();
Expand All @@ -106,14 +97,57 @@ export class SpritePlane {
if (this.framesY <= 0) this.framesY = 1

this.totalFrames = _framesX * _framesY

this.changeFrame(_frameNum)

Material.createOrReplace(this.entity)
Material.setPbrMaterial(this.entity, {
texture: Material.Texture.Common({
src: _textureFile
}),
transparencyMode: 2,
roughness: 0.9
})
MeshRenderer.setPlane(this.entity, this.setUVsFromAtlas(770, 400, 130, 112, 1024, 1024))
}

changeFrame(_frameNum: number): void {
this.frameNum = _frameNum
this.uvs = this.getUVs(_frameNum, this.framesX, this.framesY)
}

// This method is used for setting UVs in SDK7
setUVsFromAtlas(
xStart: number,
yStart: number,
width: number,
height: number,
atlasWidth: number,
atlasHeight: number
): number[] {
const uMin = xStart / atlasWidth
const vMin = yStart / atlasHeight
const uMax = (xStart + width) / atlasWidth
const vMax = (yStart + height) / atlasHeight

return [
// Front face (North)
uMin,
vMin, // Bottom Left
uMax,
vMin, // Bottom Right
uMax,
vMax, // Top Right
uMin,
vMax, // Top Left

// Back face (South)
uMax,
vMin, // Bottom Right
uMin,
vMin, // Bottom Left
uMin,
vMax, // Top Left
uMax,
vMax // Top Right
]
}
}

0 comments on commit c21def8

Please sign in to comment.