gpt4 book ai didi

java - 理解 cuboc libgdx 示例

转载 作者:行者123 更新时间:2023-12-01 12:17:32 30 4
gpt4 key购买 nike

我已经克隆并能够从我从这里获得的 Cuboc libgdx 演示生成一个功能应用程序:https://github.com/libgdx/libgdx-demo-cuboc

我试图理解 Cuboc libgdx 演示中的这段代码。我将在下面的代码中添加我的问题作为注释:

package com.badlogic.cubocy;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Pixmap;
import com.badlogic.gdx.utils.Array;

public class Map {
static int EMPTY = 0;
/***
*** why do these ints have to be in hex ?
***/
static int TILE = 0xffffff;
static int START = 0xff0000;
static int END = 0xff00ff;
static int DISPENSER = 0xff0100;
static int SPIKES = 0x00ff00;
static int ROCKET = 0x0000ff;

...

private void loadBinary () {
/***
*** how did the file "levels.png" get created ?
***/
Pixmap pixmap = new Pixmap(Gdx.files.internal("data/levels.png"));
tiles = new int[pixmap.getWidth()][pixmap.getHeight()];
for (int y = 0; y < 35; y++) {
for (int x = 0; x < 150; x++) {

/***
*** What's up with the bitwise operations?
***/
int pix = (pixmap.getPixel(x, y) >>> 8) & 0xffffff;
if (match(pix, START)) {
...
} else if (match(pix, DISPENSER)) {
...
} else if (match(pix, ROCKET)) {
...
} else {
tiles[x][y] = pix;
}
}
}

...

谢谢!

最佳答案

  1. 它们不必是十六进制,但这是查看它们与用作 map 的图像文件中对应的颜色的便捷方法。

  2. 这个游戏的 map 编辑器基本上是 MSPaint。有人在美术程序中绘制了 png 文件。图像文件中的每种颜色都与此类顶部的常量整数之一匹配。

  3. Pixmap 整数采用 RGBA 格式,但显然只使用 RGB 值。如果您查看顶部的常量 int,您会发现它们都没有使用 32 位整数的前 8 位。因此,该行上的按位运算会删除图像像素的 A 部分 (>>>8),并为我们提供一个 RGB int。我不太熟悉位移位。在使用无符号移位 >>> 而不是有符号移位 >> 之后,用 & 0xffffff 屏蔽它对我来说似乎是多余的,但也许我缺少一些东西。

关于java - 理解 cuboc libgdx 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26900690/

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