简体   繁体   中英

Java add a score counter

I have created a very simple java game, using different Textures. I want to add a score counter/label on to that game, so that every time the player does something, the score increases.

I tried using Jlabel but I had troubles getting it to show. Maybe because I use Texture as a background.

I want it to be able to style the score label, where I can change the size and position.

is there any java code that gives you a text to top right corner of the game screen in android

While you could do it in Java, Android doesn't use JLabel anyway.

You want XML.

Use a RelativeLayout to align to parent-right/end and parent-top

<RelativeLayout
    ...
    >

    <TextView
        android:id="@+id/scoreCounter"
        android:text="0"
        android:layout_alignParentTop="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentEnd="true" />

</RelativeLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM