gpt4 book ai didi

android - 如何随机改变 Sprite 的颜色

转载 作者:搜寻专家 更新时间:2023-11-01 08:25:49 26 4
gpt4 key购买 nike

我写了下面的代码:

int color = Color.argb8888(255, rand.nextInt(256), rand.nextInt(256), rand.nextInt(256));
stage.getBatch().setColor(color);

使用这段代码,我想随机更改 Sprite 的颜色。不幸的是,舞台上所有 Sprite 的颜色都变了,但我想声明我想要着色的 Sprite 。我怎样才能改进我的代码?

最佳答案

要改变单个 Sprite 的色调,使用下面的代码

Sprite mysprite;
Texture mytexture;
mytexture = new Texture("texture.png");
mysprite = new Sprite(mytexture);
mysprite.setColor(Color.WHITE.cpy().lerp(Color.BLACK, .5f));

此代码将 Sprite 的白色色调更改为黑色

关于android - 如何随机改变 Sprite 的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45335896/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com