【问题标题】:How to implement Dialog in LibGDX (unable to load skin)如何在 LibGDX 中实现 Dialog(无法加载皮肤)
【发布时间】:2018-08-21 15:48:39
【问题描述】:

我想使用 Dialog 类实现一个简单的对话框。我尝试使用此处提供的标准皮肤文件

https://github.com/libgdx/libgdx/tree/master/tests/gdx-tests-android/assets/data

  • uiskin.atlas
  • uiskin.json
  • uiskin.png
  • default.png
  • default.fnt

我下载了 RAW,但无法让它们工作。

json中的第一行:

{BitmapFont: { default-font: { file: default.fnt } },

抛出错误:

com.badlogic.gdx.utils.reflect.ReflectionException: Class not found: BitmapFont

android studio 中的整个文件以红色突出显示,表示它不符合语言规范。

我加载了另一个格式如下的文件:

{
  "com.badlogic.gdx.graphics.g2d.BitmapFont": {
    "default-font": {
      "file": "default.fnt"
    }
  },
  "com.badlogic.gdx.graphics.Color": {
    "green": {
      "a": 1,
      "b": 0,
      "g": 1,
      "r": 0
    },
    "white": {
      "a": 1,
      "b": 1,
      "g": 1,
      "r": 1
    },
    "red": {
      "a": 1,
      "b": 0,
      "g": 0,
      "r": 1
    },
    "black": {
      "a": 1,
      "b": 0,
      "g": 0,
      "r": 0
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Skin$TintedDrawable": {
    "dialogDim": {
      "name": "white",
      "color": {
        "r": 0,
        "g": 0,
        "b": 0,
        "a": 0.45
      }
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Button$ButtonStyle": {
    "default": {
      "down": "default-round-down",
      "up": "default-round"
    },
    "toggle": {
      "down": "default-round-down",
      "checked": "default-round-down",
      "up": "default-round"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.TextButton$TextButtonStyle": {
    "default": {
      "down": "default-round-down",
      "up": "default-round",
      "font": "default-font",
      "fontColor": "white"
    },
    "toggle": {
      "down": "default-round-down",
      "up": "default-round",
      "checked": "default-round-down",
      "font": "default-font",
      "fontColor": "white",
      "downFontColor": "red"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.ScrollPane$ScrollPaneStyle": {
    "default": {
      "vScroll": "default-scroll",
      "hScrollKnob": "default-round-large",
      "background": "default-rect",
      "hScroll": "default-scroll",
      "vScrollKnob": "default-round-large"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.SelectBox$SelectBoxStyle": {
    "default": {
      "font": "default-font",
      "fontColor": "white",
      "background": "default-select",
      "scrollStyle": "default",
      "listStyle": {
        "font": "default-font",
        "selection": "default-select-selection"
      }
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.SplitPane$SplitPaneStyle": {
    "default-vertical": {
      "handle": "default-splitpane-vertical"
    },
    "default-horizontal": {
      "handle": "default-splitpane"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Window$WindowStyle": {
    "default": {
      "titleFont": "default-font",
      "background": "default-window",
      "titleFontColor": "white"
    },
    "dialog": {
      "titleFont": "default-font",
      "background": "default-window",
      "titleFontColor": "white",
      "stageBackground": "dialogDim"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.ProgressBar$ProgressBarStyle": {
    "default-horizontal": {
      "background": "default-slider",
      "knob": "default-slider-knob"
    },
    "default-vertical": {
      "background": "default-slider",
      "knob": "default-round-large"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Slider$SliderStyle": {
    "default-horizontal": {
      "background": "default-slider",
      "knob": "default-slider-knob"
    },
    "default-vertical": {
      "background": "default-slider",
      "knob": "default-round-large"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Label$LabelStyle": {
    "default": {
      "font": "default-font",
      "fontColor": "white"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.TextField$TextFieldStyle": {
    "default": {
      "selection": "selection",
      "background": "textfield",
      "font": "default-font",
      "fontColor": "white",
      "cursor": "cursor"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.CheckBox$CheckBoxStyle": {
    "default": {
      "checkboxOn": "check-on",
      "checkboxOff": "check-off",
      "font": "default-font",
      "fontColor": "white"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.List$ListStyle": {
    "default": {
      "fontColorUnselected": "white",
      "selection": "selection",
      "fontColorSelected": "white",
      "font": "default-font"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Touchpad$TouchpadStyle": {
    "default": {
      "background": "default-pane",
      "knob": "default-round-large"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.Tree$TreeStyle": {
    "default": {
      "minus": "tree-minus",
      "plus": "tree-plus",
      "selection": "default-select-selection"
    }
  },
  "com.badlogic.gdx.scenes.scene2d.ui.TextTooltip$TextTooltipStyle": {
    "default": {
      "label": {
        "font": "default-font",
        "fontColor": "white"
      },
      "background": "default-pane",
      "wrapWidth": 150
    }
  }
}

我又遇到了一个错误:

com.badlogic.gdx.utils.GdxRuntimeException: 
No Drawable, NinePatch, TextureRegion, Texture, or Sprite registered with name: white

有没有人知道我可以下载并且可以工作的皮肤包?

【问题讨论】:

标签: java android libgdx


【解决方案1】:

第一种情况:

{BitmapFont: { default-font: { file: default.fnt } },

您需要使用完全限定的 Java 类名,例如 "com.badlogic.gdx.graphics.g2d.BitmapFont"

在第二种情况下:您在.json 中遗漏了一些东西,比如找不到资源(white)


查看this 存储库,其中包含许多免费的 LibGDX Scene2D GUI 皮肤。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-04-27
    • 2016-09-12
    • 2013-04-17
    • 1970-01-01
    • 2016-05-23
    • 2023-02-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多