So, my problem is, I’ve got a xml file which I’ve parsed. I’ve gotten x,y, width, and height for these objects (based on their upper left point) from the xml. Now, I want to scale these objects to any resolution when attaching them to the guiNode. I’m using quads to represent them.
If I default to 640x640, which is the resolution I used in Tiled to make the map, it looks perfect:
But if I try and do my scaling, it comes out like this:
So basically, I think I need help with a) my math and b) my understanding of quads.
Here is the code that places the images in:
[java]for(int i = 0; i < objects.size(); i++){
Geometry q = ((Geometry)((Object[])objects.get(i))[0]);
float x = ((Integer)((Object[])objects.get(i))[1]);
float y = ((Integer)((Object[])objects.get(i))[2]);
//System.out.println(x + " " + y);
q.setLocalScale(app.settings.getWidth()/(32f*20f),app.settings.getHeight()/(32f*20f),0); //scale width and height by factor
q.setLocalTranslation((x/(20f*32f)) * app.settings.getWidth(),(((32f*20)-y)/(32f*20f))*app.settings.getHeight()-32,0);
//System.out.println(q.getLocalTranslation() + " " + q.getLocalScale().y);
guiNode.attachChild(q);
}[/java]
And here is the code/math that places the red quads of arbitrary size in (with the defined x,y,width,height from top left corner):
[java]for(int i = 0;i < collide.size(); i++){
if(((TiledObjectGroup)collide.get(i)).getName().equalsIgnoreCase(“collision”)){
CollisionGroup cg = (CollisionGroup)collide.get(i);
for(int j = 0; j<cg.getGroup().size();j++){
float x = ((ObjectDetails)cg.getGroup().get(j)).getX();
float y = ((ObjectDetails)cg.getGroup().get(j)).getY();
float w = ((ObjectDetails)cg.getGroup().get(j)).getWidth();
float h = ((ObjectDetails)cg.getGroup().get(j)).getHeight();
x = (x/(20f*32f)) * app.settings.getWidth(); //Divide x by original width by original width, then multiply with new width
y = ((1- (y/(32f*20f)))*app.settings.getHeight())-h; // Divide 1 - y/original height (to flip y), then mulitply by new height
w = w * app.settings.getWidth()/(32f*20f); //Scale width
h = h * app.settings.getHeight()/(32f*20f); //Scale height
System.out.println(w + " " + h + " " + x + " " + y);
Quad b = new Quad(w,h); // create cube shape
Geometry geom = new Geometry("Box", b); // create cube geometry from the shape
Material mat = new Material(assetManager,
"Common/MatDefs/Misc/Unshaded.j3md"); // create a simple material
mat.setColor("Color", ColorRGBA.Red); // set color of material to blue
geom.setMaterial(mat);
// geom.addControl(rbc);
Node box = new Node("box");
//geom.scale(w,h,0);
box.attachChild(geom);
//bas.getPhysicsSpace().add(rbc);
guiNode.attachChild(box);
box.setLocalTranslation(x,y,0);
}
}
}
[/java]
Anyone know what I’m doing wrong?