Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6652957
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T01:12:25+00:00 2026-05-26T01:12:25+00:00

I been working in a project with a team for a Software Engineering class

  • 0

I been working in a project with a team for a Software Engineering class and we think that using the parallax scrolling will help our game to look really nice but we are not really sure if our idea for implementation it’s the correct one, so I hope that someon will give us some guidance about our plan.

First, we have three classes, Level, Tileset, Layer, the first one has two vectors of Layers and Tilesets, so our idea is load all the data from a TMX file of the first level in a vector>, but we only draw the part of the map that it’s currently in camera, so inside a cycle we draw every layer, but we’re not sure how defined a velocity for each layer so the parallax scrolling works like it supposed.

PD: If someone need more information, don’t doubt in ask.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T01:12:25+00:00Added an answer on May 26, 2026 at 1:12 am

    Sorry for the late answer. I already find out the problem, I leave the new code so maybe someone will find this useful. The problem was handling the different offset in each row of the tilemap, but now it’s solved.

    void Tilemap::drawTilemap(int indexTileset)
    {
        GLfloat offsetXTemp = offset.x;
    
        offsetXTemp = transformOffsetXToIntervalValues(offset.x);
    
        GLfloat variableSizeTile = 32.f;
    
        GLfloat widthTilesetImage = tilesetList.at(indexTileset).getWidthImage();
        GLfloat heightTilesetImage = tilesetList.at(indexTileset).getHeightImage();
    
        int widthMap = (1280 / (int)sizeTiles) + 1;
        int heigthMap = (int) ceil( 720.0f / sizeTiles );
    
        glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    
        glEnableClientState( GL_VERTEX_ARRAY );
        glEnableClientState( GL_TEXTURE_COORD_ARRAY );  
    
        glBindTexture( GL_TEXTURE_2D, tilesetList.at(indexTileset).getTexture() );
    
        GLfloat posXPrevious = 0.0f, posXPreviousOnTexture = 0.0f;
    
        for (int i = 0; i < heigthMap; i++)
        {
            int startX = (int)floor(offset.x/sizeTiles);
            posXPrevious = 0.0f;
    
            posXPrevious -= offsetXTemp;
            variableSizeTile = 32.f;
    
            for (int j = 0; j < widthMap; j++) 
            {
                if ( startX == widthLevelInTiles )
                {
                    break;
                }
    
                int frameIndex = layerMap[i][startX].getID();
    
                if ( frameIndex == 0 )
                { 
                    startX++;
                    variableSizeTile = 32.f;
                    posXPrevious = posXPrevious + variableSizeTile;
    
                    continue; 
                }
    
                if ( j == 0 && offsetXTemp != sizeTiles)
                {
                    posXPreviousOnTexture = offsetXTemp/widthTilesetImage;
                    variableSizeTile -= offsetXTemp;
                    posXPrevious = 0.0f;
                }
    
                else 
                { 
                    variableSizeTile = 32.f; 
                    posXPreviousOnTexture = 0.0f;
                }
    
                if ( j == 40 )
                {
                    variableSizeTile = offsetXTemp;
                }
    
                frameIndex -= 1;
    
                const GLfloat tileX = posXPrevious;
                const GLfloat tileY = sizeTiles * i;
                posXPrevious = tileX + variableSizeTile;
    
                const GLfloat verts[] = {
                        tileX, tileY,
                        tileX + variableSizeTile, tileY,
                        tileX + variableSizeTile, tileY + sizeTiles,
                        tileX, tileY + sizeTiles
                };
    
                const GLfloat textureWidth = variableSizeTile / (GLfloat)widthTilesetImage;
                const GLfloat textureHeight = sizeTiles / (GLfloat)heightTilesetImage;
                const int numFramePerRow = (int)widthTilesetImage / (int)sizeTiles;
                const GLfloat textureX = ( (frameIndex % numFramePerRow) * sizeTiles/(GLfloat)widthTilesetImage ) 
                                        + posXPreviousOnTexture;
                const GLfloat textureY = ( frameIndex / numFramePerRow ) * textureHeight;
    
                const GLfloat texVerts[] = {
                        textureX, textureY,
                        textureX + textureWidth, textureY,
                        textureX + textureWidth, textureY + textureHeight,
                        textureX, textureY + textureHeight
                };
    
                glVertexPointer(2, GL_FLOAT, 0, verts);
                glTexCoordPointer(2, GL_FLOAT, 0, texVerts);
                glDrawArrays(GL_QUADS, 0, 4);
    
                startX++;
            }   
        }
    
        glDisableClientState( GL_VERTEX_ARRAY );            
        glDisableClientState( GL_TEXTURE_COORD_ARRAY );
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been working on a project that accesses the WMI to get information about
I've been working on a project that can't be described as 'small' anymore (40+
I have been working on a project that has 2 interfaces - windows forms
I have been working on standardizing the source control structure for our Team Foundation
I've been working on a fairly large C++ project that surprisingly uses MS Access
I've got a django project working on a development server(ubuntu) that we have been
I've been working on a project that uses a frontloader to handle all requests
Folks I am working in UI design in a project where our team chose
I have been using SCM for myself, but now I am working in team-of-two
The project my team has been working on has reached a point where we

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.