【问题标题】:How can i create a circle which has a number in?如何创建一个有数字的圆圈?
【发布时间】:2023-03-17 09:32:01
【问题描述】:

我正在使用 AndEngine 编写一个 Android 游戏。我想创建一个包含数字的圆圈,如下图所示:

【问题讨论】:

    标签: java android andengine


    【解决方案1】:

    嗯,我想最简单的方法就是把这样的图片放在哈哈。您始终可以使用带有圆圈的图像,然后将带有数字的文本叠加在其顶部。

    【讨论】:

    • 我会创建很多。所以我不能使用图像来获得良好的性能。
    • 您可以使用简单的游戏引擎来处理图像。如果它们不移动,它们不应该是处理器密集型的。即使这样,大多数引擎也可以毫无问题地处理 20 或 30 个移动精灵,即使对所有这些精灵都应用了碰撞系统。
    • 使用源是位图的纹理不会影响您的性能,就像使用源是从绘画中绘制的位图的纹理一样。事实上,它们将是相同的。因为要在 GL 中显示圆圈,它必须首先是位图。
    【解决方案2】:

    类似这样的:

    circle.xml(在 res/drawable 中)

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android"
        android:shape="oval" >
    
        <solid android:color="#aaf" />
    
    </shape>
    

    和 circletext.xml(在 res/layout 中):

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:orientation="vertical" >
    
        <TextView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:layout_gravity="center"
            android:background="@drawable/circle"
            android:gravity="center"
            android:shadowColor="@android:color/white"
            android:shadowRadius="10.0"
            android:text="4"
            android:textColor="@android:color/black"
            android:textSize="18sp" />
    
    </FrameLayout>
    

    看起来像这样:

    【讨论】:

    • 我向 TextView 添加了以下属性,以便为更大的数字添加更好的润色。 android:layout_width="wrap_content" android:layout_height="wrap_content" android:minHeight="14dp" android:minWidth="14dp" android:maxHeight="14dp"
    猜你喜欢
    • 1970-01-01
    • 2019-07-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多