libgdx实现淡入淡出过渡

这篇具有很好参考价值的文章主要介绍了libgdx实现淡入淡出过渡。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

libgdx实现淡入淡出过渡

libgdx实现淡入淡出过渡,环境jdk17+libgdx 1.12.02023年11月1日11:02:50最新

依赖

<properties>
        <maven.compiler.source>17</maven.compiler.source>
        <maven.compiler.target>17</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <gdx.version>1.12.0</gdx.version>
    </properties>

    <dependencies>
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx</artifactId>
            <version>${gdx.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-backend-lwjgl3 -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-backend-lwjgl3</artifactId>
            <version>${gdx.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-platform -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-platform</artifactId>
            <version>${gdx.version}</version>
            <classifier>natives-desktop</classifier>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-freetype -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-freetype</artifactId>
            <version>${gdx.version}</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/com.badlogicgames.gdx/gdx-freetype-platform -->
        <dependency>
            <groupId>com.badlogicgames.gdx</groupId>
            <artifactId>gdx-freetype-platform</artifactId>
            <version>${gdx.version}</version>
            <classifier>natives-desktop</classifier>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13.2</version>
        </dependency>

        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>2.0.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-simple -->
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-simple</artifactId>
            <version>2.0.9</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.projectlombok/lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.30</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>17</source>
                    <target>17</target>
                    <!-- 编译后保持方法形参名称不变 -->
                    <!--<compilerArgs>
                        <arg>-parameters</arg>
                    </compilerArgs>-->
                </configuration>
            </plugin>
        </plugins>
    </build>

    <repositories>
        <repository>
            <id>tencent</id>
            <name>tencent</name>
            <layout>default</layout>
            <url>http://mirrors.cloud.tencent.com/nexus/repository/maven-public/</url>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>nexus</id>
            <name>Nexus</name>
            <layout>default</layout>
            <url>https://s01.oss.sonatype.org/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <releases>
                <enabled>true</enabled>
            </releases>
        </repository>
        <repository>
            <id>aliyunmaven</id>
            <url>https://maven.aliyun.com/repository/public</url>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>false</enabled>
            </snapshots>
        </repository>
    </repositories>

实现

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.scenes.scene2d.InputEvent;
import com.badlogic.gdx.scenes.scene2d.InputListener;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.AlphaAction;
import com.badlogic.gdx.scenes.scene2d.ui.Image;
import com.badlogic.gdx.utils.ScreenUtils;
import org.junit.Test;

/**
 * @author lingkang
 * created by 2023/11/1
 */
public class TestFade extends ApplicationAdapter {
    @Test
    public void test() {
        Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
        config.setForegroundFPS(30);
        config.setTitle("yzcy");
        config.setWindowedMode(800, 600);
        new Lwjgl3Application(this, config);
    }

    Stage stage;
    Image img;
    Texture texture;
    long inTime = 0l;

    @Override
    public void create() {
        stage = new Stage();
        texture = new Texture(Gdx.files.internal("badlogic.jpg"));
        img = new Image(texture);
        img.setSize(texture.getWidth(), texture.getHeight());
        img.setOrigin(img.getWidth() / 2, img.getHeight() / 2);
        stage.addActor(img);
        
        /**
        // 顺序淡入淡出
        SequenceAction alpha = Actions.sequence(
            Actions.fadeOut(0f),
            Actions.delay(2),
            Actions.fadeIn(1f),
            Actions.delay(5),
            Actions.fadeOut(1f)
        );
        img.addAction(alpha);
        */
        float dur = 0.7f;
        //  Actions.moveBy 移动   Actions.scaleBy 大小    Actions.rotate 旋转
        // 淡入
        AlphaAction fadeIn = Actions.fadeIn(dur);
        img.addAction(fadeIn);
        // 点击图片,淡出
        AlphaAction fadeOut = Actions.fadeOut(dur);
        img.addListener(new InputListener() {
            @Override
            public boolean touchDown(InputEvent event, float x, float y, int pointer, int button) {
                img.clearActions();
                img.addAction(fadeOut);
                return true;
            }
        });

        Gdx.input.setInputProcessor(stage);
    }

    @Override
    public void render() {
        ScreenUtils.clear(Color.WHITE);
        stage.act();
        stage.draw();
    }

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

效果

libgdx实现淡入淡出过渡,libgdx,游戏开发,java,libgdx,游戏效果文章来源地址https://www.toymoban.com/news/detail-736591.html

到了这里,关于libgdx实现淡入淡出过渡的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 小程序轮播,上下两层图片,底层渐变淡入淡出,上层动画划入效果

    先看效果: 如果大家有喜茶小程序,可以进入查看首页轮播效果图,大概就是那个效果。 捋一下我开发过程的思路,一共有两个。 第一个思路: 用微信小程序的组件,swiper实现上层透明照片的轮播效果,底层的照片根据swiper组件的bindchange,bindtransition,bindanimationfinish三个方法

    2024年02月15日
    浏览(32)
  • unity实现UI文字和图片淡入淡出

    using UnityEngine; using UnityEngine.UI; public class CrossFadeAlphaTest : MonoBehaviour {     Graphic graphicText;     Graphic graphicImage;     public Text  text01;//文字     public Image image1;//图片     void Start()     {         graphicText = text01.GetComponentGraphic();         graphicImage = image1.GetComponentGraphic();    

    2024年04月16日
    浏览(23)
  • UE4 使用控件蓝图的动画功能实现UI的淡入淡出

    效果: 步骤: 首先PS一张背景纯黑,边缘有羽化效果的图片: 新建一个控件蓝图,创建一个图像和按钮控件,控件的初始位置如下所示,设置图像一开始为完全透明 新建两个动画,分别命名为“向左移动”和“向右移动” 在时间轴上添加对按钮和图像的控制 按钮主要是对

    2024年02月17日
    浏览(32)
  • Vue过渡与动画的实现效果

     使用 transition 标签配合 CSS3 过渡实现【不完整代码】: Vue 还提供了四个 class 类名,分别是进入的起点(v-enter)进入的终点(v-enter-to)离开的起点(v-leave)离开的终点(v-leave-to) 注 :进入的起点 和 离开的起点 就相当于 CSS3 动画里的 from  进入的终点 和 离开的终点 就相

    2024年02月02日
    浏览(30)
  • 如何使用CSS实现一个平滑过渡效果?

    前端入门之旅:探索Web开发的奇妙世界 欢迎来到前端入门之旅!感兴趣的可以订阅本专栏哦!这个专栏是为那些对Web开发感兴趣、刚刚踏入前端领域的朋友们量身打造的。无论你是完全的新手还是有一些基础的开发者,这里都将为你提供一个系统而又亲切的学习平台。在这个

    2024年02月12日
    浏览(33)
  • 【CSS】简记CSS效果:通过transition(动画过渡属性)实现侧边栏目滑入滑出

    在资金明细的页面中,点击按钮时筛选区域从左侧滑出,完成筛选点击确认后调用接口完成数据查询,筛选区域滑入左侧; https://www.cnblogs.com/yadiblogs/p/10145625.html  

    2024年02月10日
    浏览(32)
  • 【游戏开发实战】Unity实现类似GitHub地球射线的效果(LineRenderer | 贝塞尔曲线)

    一、前言 嗨,大家伙,我是新发。 好久不见,这是2022年第一篇博客,今天有同学私信我,问我在 Unity 中如何实现这种地球辐射线的效果, 这一看,我就想到了 GitHub 主页的地球射线, 那么,今天就来讲讲如何实现这个效果吧~ 本文最终效果如下: 本文工程源码见文章末尾

    2024年02月06日
    浏览(81)
  • VueCLI核心知识4:动画效果、过渡效果

    【代码】 1.安装 2.导入 3.使用

    2024年02月19日
    浏览(36)
  • 30.CSS文本悬停过渡效果

    index.html css

    2024年02月07日
    浏览(29)
  • 浅谈css的过渡效果transition的使用

    CSS 的 transition 允许您对 CSS 属性的更改进行动画处理,这对于在网站上创建平滑和视觉上吸引人的效果非常有用。 要创建一个过渡,您需要使用 transition 属性。该属性允许您指定要过渡的 CSS 属性,以及过渡的持续时间、时间函数和延迟。以下是 transition 属性的语法: prope

    2024年02月02日
    浏览(34)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包