缺少LableStyle字体

时间:2015-06-27 12:56:29

标签: android libgdx

我为我的游戏获得了这个课程,我想要用CourierNew编写Label高分。 .fnt和.png文件位于assets文件夹中。

angular.module('myApp', ['ngAnimate'])
            .controller("myController",function($scope){


                $scope.toggle =true; 


                $scope.list=[
                {name:'bla',age:28,img: 'https://s3.amazonaws.com/uifaces/faces/twitter/brad_frost/128.jpg'},
                {name:'blabla',age:38,img: 'https://s3.amazonaws.com/uifaces/faces/twitter/mlane/128.jpg'},
                {name:'blaba',age:23, img:'https://s3.amazonaws.com/uifaces/faces/twitter/felipenogs/128.jpg'},
                {name:'blablala',age:56, img:'https://s3.amazonaws.com/uifaces/faces/twitter/adellecharles/128.jpg'}
                ];


                $scope.addPerson= function(){
                    $scope.list.push({name:$scope.name,age:$scope.age});
                    $scope.name="";
                    $scope.age="";
                };
            });

但是我总是得到错误:

package com.joelbrun.jetskirider.screens;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.ui.Button;
import com.badlogic.gdx.scenes.scene2d.ui.CheckBox;
import com.badlogic.gdx.scenes.scene2d.ui.Label;
import com.badlogic.gdx.scenes.scene2d.ui.Table;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;

public class MainMenu implements Screen {

    private Stage stage;
    private Table table;
    private Label highscore;
    private Button startButton, removeAdsButton;
    private CheckBox muteCheckbox;
    private BitmapFont CourierNew;
    public int score = 0;

    @Override
    public void show() {
        stage = new Stage();
        table = new Table();
        table.setFillParent(true);
        CourierNew = new BitmapFont(Gdx.files.internal("CourierNew.fnt"), false);

        Button.ButtonStyle startButtonStyle = new Button.ButtonStyle();
        startButtonStyle.up = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("startButtonUp.png"))));
        startButtonStyle.down = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("startButtonDown.png"))));

        Button.ButtonStyle removeAdsButtonStyle = new Button.ButtonStyle();
        removeAdsButtonStyle.up = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("removeAdsButtonUp.png"))));
        removeAdsButtonStyle.down = new TextureRegionDrawable(new TextureRegion(new Texture(Gdx.files.internal("removeAdsButtonDown.png"))));

        CheckBox.CheckBoxStyle muteCheckboxStyle = new CheckBox.CheckBoxStyle();
        muteCheckboxStyle.checkboxOn = new TextureRegionDrawable(new TextureRegion(new Texture("muteCheckboxChecked.png")));
        muteCheckboxStyle.checkboxOff = new TextureRegionDrawable(new TextureRegion(new Texture("muteCheckboxUnchecked.png")));

        Label.LabelStyle highscoreStyle = new Label.LabelStyle(CourierNew, Color.YELLOW);

        String formatted = Integer.toString(score);
        startButton = new Button(startButtonStyle);
        removeAdsButton = new Button(removeAdsButtonStyle);
        muteCheckbox = new CheckBox(null, muteCheckboxStyle);
        highscore = new Label(formatted, highscoreStyle);

        table.add(startButton);
        table.debug();
        stage.addActor(table);


    }

    @Override
    public void render(float delta) {
        Gdx.gl.glClearColor(0,0,0,1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);

        stage.act(delta);
        stage.draw();
    }

    @Override
    public void resize(int width, int height) {

    }

    @Override
    public void pause() {

    }

    @Override
    public void resume() {

    }

    @Override
    public void hide() {

    }

    @Override
    public void dispose() {
        stage.dispose();
    }
}

有什么问题?我已经尝试了很多...希望任何人都可以提供帮助

1 个答案:

答案 0 :(得分:1)

如果您按照自己发布的追踪信息进行追踪,则会引导您进入

com.badlogic.gdx.scenes.scene2d.ui.Label.setStyle(Label.java:77)

如果您查看code,您会看到(在setStyle方法中):

if (style.font == null) throw new IllegalArgumentException("Missing LabelStyle font.");

您看到的例外情况。所以问题是初始化Style muteCheckboxmuteCheckboxStyle)的null对象有font作为其&#39}。 muteCheckbox = new CheckBox(null, muteCheckboxStyle);。这可以很容易地修复。在致电muteCheckboxStyle初始化font' s muteCheckboxStyle.font = CourierNew;

之前
appID/subscriptions?access_token=appID|appToken&object=user&fields=about,quotes,inbox&callback_url=http://example.com/callback.php&verify_token=tok