所以我创建一个精灵并使用不同的类将其绘制到屏幕上。Libgdx java精灵大小问题
我现在想要在每个屏幕上将其缩放为相同的长宽比/大小。
我试图这样做,通过使用此代码:
public Player(Vector2 position, float width, float height, float rotation, float speed)
{
super(speed, rotation, width, height, position);
}
public void update()
{
width = Gdx.graphics.getWidth()/10;
height = Gdx.graphics.getHeight()/10;
}
但是,这并不工作,它什么都不做。
我也尝试将宽度和高度设置为例如100的静态值100。但这也不起作用。
谢谢你的帮助! :)
编辑:加入基地和派生类:
下面是实体类的代码:
public abstract class Entity {
public void setPosition(Vector2 position) {
this.position = position;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
public float getHeight() {
return height;
}
public void setHeight(float height) {
this.height = height;
}
public Rectangle getBounds() {
return bounds;
}
public void setBounds(Rectangle bounds) {
this.bounds = bounds;
}
}
下面是该MoveEntity类的代码:
public MoveEntity(float speed, float rotation,
float width, float height,
Vector2 position) {
super(position, width, height);
this.speed = speed;
this.rotation = rotation;
vel = new Vector2(0, 0);
}
public Vector2 getVel() {
return vel;
}
public void setVel(Vector2 target) {
this.vel = target;
}
public float getRotation() {
return rotation;
}
public void setRotation(float r) {
..............///
是''Player'的Actor'一个子类?如果是,你可以使用'setSize()'。我不知道LibGDX API中的任何公共'width'或'height'字段,所以我的猜测是你正在修改你定义的一些字段。在这种情况下,你不能指望LibGDX知道你改变了这些字段的值。 –
Player是我创建的另一个类“MoveEntity”的子类下面是MoveEntity类的代码:package com.fam.entities; public MoveEntity(float speed,float rotation,float width,float height,Vector2 position) \t { \t \t super(position,width,height); \t \t \t \t this.speed = speed; \t \t \t \t this.rotation = rotation; \t \t \t \t vel = new Vector2(0,0); \t} \t \t 公共Vector2 getVel() \t { \t \t返回VEL; \t} \t \t 公共无效setVel(Vector2目标) \t { \t \t this.vel =目标; \t} \t \t 公共浮动getRotation() \t { \t \t返回转动; \t} \t \t公共无效setRotation(浮动R) \t } – Dumbostyle
而MoveEntity是子类的类 “实体” 具有这种代码: 公共抽象类实体 { \t公共无效setPosition两种(Vector2位置) \t { \t \t this。position = position; \t} \t public float getWidth(){ \t \t return width; \t} \t公共无效setWidth(浮动宽度) \t { \t \t this.width =宽度; \t} \t public float getHeight(){ \t \t return height; \t} \t公共无效自动调用setHeight(浮动高度) \t { \t \t this.height =高度; \t} \t公共矩形的getBounds(){ \t \t返回界限; \t} \t公共无效的setBounds(矩形范围) \t { \t \t this.bounds =界限; \t} } – Dumbostyle