优化hover效果
This commit is contained in:
@@ -36,7 +36,8 @@ export class TopBar extends Laya.Script {
|
||||
@property(Laya.Box)
|
||||
public obj_items: Laya.Box
|
||||
|
||||
private items: Map<string, Laya.Label> = new Map()
|
||||
private item_sprites: Map<string, Laya.Sprite> = new Map()
|
||||
private item_labels: Map<string, Laya.Label> = new Map()
|
||||
|
||||
onStart(): void {
|
||||
// 如果是第一次以横屏启动游戏需要创建经典关卡
|
||||
@@ -79,9 +80,11 @@ export class TopBar extends Laya.Script {
|
||||
for (let i = 0; i < this.obj_items.numChildren; i++) {
|
||||
const obj = this.obj_items.getChildAt(i)
|
||||
const value = config.DIFFICULTY_LIST[i]
|
||||
const sprite = obj.getChildByName("Sprite") as Laya.Sprite
|
||||
this.item_sprites.set(value, sprite)
|
||||
const label = obj.getChildByName("Label") as Laya.Label
|
||||
label.text = value
|
||||
this.items.set(value, label)
|
||||
this.item_labels.set(value, label)
|
||||
const common = obj.getComponent(CommonData)
|
||||
common.strValue = value
|
||||
obj.on(Laya.Event.CLICK, this, (evt: Laya.Event) => {
|
||||
@@ -140,10 +143,18 @@ export class TopBar extends Laya.Script {
|
||||
}
|
||||
|
||||
updateDifficulty(difficulty: string): void {
|
||||
this.items.forEach((label: Laya.Label) => {
|
||||
this.item_sprites.forEach((sprite: Laya.Sprite) => {
|
||||
sprite.graphics.clear()
|
||||
sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#f5f7fb", "#0e2a53", 5)
|
||||
})
|
||||
const sprite = this.item_sprites.get(difficulty)
|
||||
sprite.graphics.clear()
|
||||
sprite.graphics.drawRoundRect(0, 0, sprite.width, sprite.height, 12, 12, 12, 12, "#f5f7fb", "#1d5cdc", 5)
|
||||
|
||||
this.item_labels.forEach((label: Laya.Label) => {
|
||||
label.color = "#0e2a53"
|
||||
})
|
||||
const label = this.items.get(difficulty)
|
||||
const label = this.item_labels.get(difficulty)
|
||||
label.color = "#1d5cdc"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,15 +4,22 @@ const { regClass, property } = Laya;
|
||||
export class CommonHover extends Laya.Script {
|
||||
declare owner : Laya.Box;
|
||||
|
||||
@property(Boolean)
|
||||
public hoverAlpha: boolean = true
|
||||
|
||||
|
||||
onAwake(): void {
|
||||
this.owner.on(Laya.Event.MOUSE_OVER, this, ()=>{
|
||||
Laya.Render.canvas.style.cursor = "pointer"
|
||||
this.owner.alpha = 0.7
|
||||
if (this.hoverAlpha) {
|
||||
this.owner.alpha = 0.7
|
||||
}
|
||||
})
|
||||
this.owner.on(Laya.Event.MOUSE_OUT, this, ()=>{
|
||||
Laya.Render.canvas.style.cursor = ""
|
||||
this.owner.alpha = 1
|
||||
if (this.hoverAlpha) {
|
||||
this.owner.alpha = 1
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user