P
P
Pavel Dmitriev2015-01-07 15:55:23
Android
Pavel Dmitriev, 2015-01-07 15:55:23

libgdx for android. How to convert sprite coordinates to texture coordinates?

I need to understand the logic of coordinate systems. I have machine objects. I display them as SPRITES. Otherwise it is impossible, because only sprites can be rotated. I draw the field (stadium) as a texture (that is, NOT AS A SPRITE). Otherwise it is impossible because only textures can be scrolled across the screen (sprites cannot be scrolled). So, it turned out that textures and sprites are displayed in different coordinates! How to convert sprite coordinates to texture coordinates?
//Screen coordinates
m_screenRectangle.set(0, 0, m_camera.viewportWidth, m_camera.viewportHeight);
//Load the stadium texture from the file
m_roadTexture = new Texture(Gdx.files.internal("road_map.png"));
// Create a region
m_myRoadTexture = new TextureRegion(
m_roadTexture,
(int)m_roadRectangle.x, (int)m_roadRectangle.y,
(int)m_roadRectangle.width, (int)m_roadRectangle.height
)
//Set the stadium
viewport m_myRoadTexture.setRegion(
(int)m_roadRectangle.x, (int)m_roadRectangle. y,
(int)m_roadRectangle.width, (int)m_roadRectangle.height
)
//Display the stadium texture
batch.draw(m_myRoadTexture, m_screenRectangle.x, m_screenRectangle.y, m_screenRectangle.width, m_screenRectangle.height);
//NOW I WANT TO DRAW MY SPRITE ON THE STADIUM SURFACE
//Prepare my sprite for display:
MY_SPRITE.setBounds(MY_SPRITE_x, MY_SPRITE_y, MY_SPRITE_width, MY_SPRITE_height);
MY_SPRITE.setOriginCenter();
//Display the sprite on the surface of the stadium
MY_SPRITE.draw(batch);
As a result, I see:
the SPRITE is displayed on the surface of the stadium, but NOT IN THE PLACE where it is necessary!
At the same time, on different devices, the position of the sprite is different!
QUESTION: What am I doing wrong?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question