Jump to content

Trixt0r Java libGdx importer - getWidth/Height method?


Nem

Recommended Posts

Is there a getWidth / getHeight method using the Trixt0r Java importer api? I am attempting to implement the api but I need to getWidth/getHeight so I can offset for player size when determining collision with a specific tile (tmx Tile maps)

I like to use this simple collision check in addition to other forms of collision with objects.

This is kind of what I want to do...I check to see if movement is allowed here:

public boolean canPlayerMove(float x, float y)

{

boolean movementAllowed = true;

// offset for player size.

x += getWidth()/1.5f;

y += getHeight() / 4;

if (isCellBlocked(x,y))

{

movementAllowed = false;

}

return movementAllowed;

}

Link to comment
Share on other sites

Use


Rectangle rect = getBoundingRectangle(null);
float width = rect.size.width;
float height = rect.size.height;
//Do stuff

getBoundingRectangle() returns always the same object reference!

But you should know that calculating the rectangle of a player can give you many different results, because not every animation has the same bounding box.

You could use boxes in Spriter instead. Those will give you always the same size.

-Trixt0r

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...