作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经克隆并能够从我从这里获得的 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;
}
}
}
...
谢谢!
最佳答案
它们不必是十六进制,但这是查看它们与用作 map 的图像文件中对应的颜色的便捷方法。
这个游戏的 map 编辑器基本上是 MSPaint。有人在美术程序中绘制了 png 文件。图像文件中的每种颜色都与此类顶部的常量整数之一匹配。
Pixmap 整数采用 RGBA 格式,但显然只使用 RGB 值。如果您查看顶部的常量 int,您会发现它们都没有使用 32 位整数的前 8 位。因此,该行上的按位运算会删除图像像素的 A 部分 (>>>8
),并为我们提供一个 RGB int。我不太熟悉位移位。在使用无符号移位 >>>
而不是有符号移位 >>
之后,用 & 0xffffff
屏蔽它对我来说似乎是多余的,但也许我缺少一些东西。
关于java - 理解 cuboc libgdx 示例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26900690/
我已经克隆并能够从我从这里获得的 Cuboc libgdx 演示生成一个功能应用程序:https://github.com/libgdx/libgdx-demo-cuboc 我试图理解 Cuboc l
我是一名优秀的程序员,十分优秀!