0
以下代碼旨在使用圖像條和畫布上的一些指甲在屏幕上繪製數字,但不顯示。無法剪裁/裁剪圖像
1)當我評論/刪除「setSourceRect」時,它顯示完整的圖像。 2)initnails功能未顯示任何
package com.myGame.mavenproject3.core;
import org.jbox2d.collision.shapes.CircleShape;
import playn.core.*;
import static playn.core.PlayN.assetManager;
import static playn.core.PlayN.graphics;
public class mavenproject3 implements Game {
Canvas canvas;
private float radius;
Image pointsFontImage;
GroupLayer pointsLayer;
@Override
public void init() {
// create and add background image layer
int width = 640;
int height = 480;
CanvasImage bgImage = graphics().createImage(width, height);
canvas = bgImage.canvas();
canvas.setFillColor(0xff87ceeb);
canvas.fillRect(0, 0, width, height);
ImageLayer bg = graphics().createImageLayer(bgImage);
graphics().rootLayer().add(bg);
pointsLayer = graphics().createGroupLayer();
pointsLayer.setScale(3.0f, 3.0f);
pointsFontImage = assetManager().getImage("images/font.png");
graphics().rootLayer().add(pointsLayer);
}
@Override
public void paint(float alpha) {
// the background automatically paints itself, so no need to do
anything here!
}
int points = 50;
@Override
public void update(float delta) {
initNails();
float x = 0f;
pointsLayer.clear();
for (char c : Integer.toString(points).toCharArray()) {
ImageLayer digit = graphics().createImageLayer(pointsFontImage);
digit.setSourceRect(((c - '0' + 9) % 10) * 16, 0, 16, 16);
pointsLayer.add(digit);
digit.setTranslation(x, 0f);
x += 16f;
}
}
@Override
public int updateRate() {
return 25;
}
public void initNails() {
for (int x = 100; x < 300 - 100; x += 50) {
for (int y = 150; y < 450; y+= 100) {
canvas.setFillColor(0xffaaaaaa);
canvas.fillCircle(x, y, radius);
CircleShape circleShape = new CircleShape();
circleShape.m_radius = 5f*2;
circleShape.m_p.set(x*2,
y*2);
}
}
}
}