我想在处理java中继续旋转FontAwesome的图标。(准确地说是 FA 旋转图标。(\f110(
链接到效果:示例
我的图标创建函数
public void drawIcon(int size, String icon, float custom_height) {
font = createFont("fontawesome-webfont.ttf",size);
textFont(font);
if(icon != null && !icon.trim().isEmpty()) {
text(icon, width / 2, height / custom_height);
}
}
初始化对象 + 调用方法
为了创建我的图标,我初始化了一个对象并在 draw((-method中调用了我的函数:
Content content = new Content(); // content object
PFont font; // font object
public void draw() {
content.drawIcon(46, "uf110", 7);
}
我从文档中找到了旋转/平移方法,但无法找出连续旋转此图标 360 度的正确参数。
尝试
public void draw() {
rotate(degrees(360));
content.drawIcon(46, "uf110", 7);
}
我建议setup()
一次加载字体,而不是在drawIcon()
中每秒加载多次。
加载字体并调用 textFont()
后,您只需使用 text()
即可。
例如
PFont font; // font object
public void setup() {
font = loadFont("fontawesome-webfont.ttf",46);
textFont(font);
}
public void drawIcon(String icon, float custom_height) {
if(icon != null && !icon.trim().isEmpty()) {
text(icon, width / 2, height / custom_height);
}
}
在旋转方面,目前您正在连续指定相同的角度。您可能想做的是创建一个变量来跟踪当前角度,递增角度并将其传递给rotate()
in draw()
.
PFont font; // font object
int angle = 0;
public void setup() {
font = loadFont("fontawesome-webfont.ttf",46);
textFont(font);
}
public void drawIcon(String icon, float custom_height) {
if(icon != null && !icon.trim().isEmpty()) {
text(icon, width / 2, height / custom_height);
}
}
public void draw() {
//increment angle (angle++; would to the same, but hopefully expanded version is easier to read)
angle = angle + 1;
rotate(degrees(angle));
content.drawIcon("uf110", 7);
}
请务必同时查看旋转处理示例。
您可能会注意到符号可能不会从中心旋转。这将要求您使用pushMatrix();/popMatrix();
调用使用多个坐标空间。请阅读 2D 转换教程,了解有关如何执行此操作的详细信息。