Welcome, Guest. Please login or register. Did you miss your activation email?

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Topics - gingerBill

Pages: [1]
1
General / Tilemap engine causing textures to move when view is moved.
« on: August 19, 2013, 01:48:25 pm »
Hi I've been make this game about a fortnight now and I've been having this problem with the tiles/blocks being rendered when the view is moved.

I've been fixing the view to the character but when the character/view is moved in the y-axis (and sometimes the x-axis but very rare) the tiles seem have these lines:



I've figured out that these lines are cause by the texturerect of the tile (which is a sprite) is being moved cause some of the rest of the texture to be show in it. The Blue lines are where texture is transparent and the brown lines on some of the grass tiles, the texture is showing another tile.


I would show some minimal code if I could but I cannot seem to replicate this on a small level so here are snippets of my code:

Place tiles into sprites
m_tiles => std::Vector<sf::Sprite>
terrain2.png is a 256x256 png containing 256 tiles (akin to older version of minecraft)

for (uint8_t y = 0; y < 16; y++)
{
        for (uint8_t x = 0; x < 16; x++)
        {
                sf::Sprite stemp;
                stemp.setTexture(textureManager.getTexture("res/image/terrain2.png"));
                stemp.setTextureRect( sf::IntRect(16*x, 16*y, 16, 16) );
                stemp.setOrigin(8, 8);
                m_tiles.push_back(stemp);
        }
}
 

Display Tiles
mapLevel => std::vector< std::vector<uint8_t> > this way I call a tile like mapLevel[x][y]

// Only display what is on screen
        int drawRangeX = window.getSize().x/64;
        int drawRangeY = window.getSize().y/64;

// Add one to draw range
        drawRangeX++;
        drawRangeY++;

        for (unsigned int y = std::max((m_character.getPosition().y/16.0f)-drawRangeY, 0.0f);
             y < std::min((m_character.getPosition().y/16.0f)+drawRangeY, (float)(gridSize.y-1)); y++)
        {
                for (unsigned int x = std::max((m_character.getPosition().x/16.0f)-drawRangeX, 0.0f);
                     x < std::min((m_character.getPosition().x/16.0f)+drawRangeX, (float)(gridSize.x-1)); x++)
                {
                        uint8_t tileId = mapLevel[x][y];
                        if (tileId != 0x00)
                        {
                                switch (tileId) // used to "randomize" tiles or get specific tile
                                {
                                case 0x05: // Grass
                                        tileId += (x+y)%2;
                                        break;
                                case 0x30: // Ore
                                        tileId += (3*x + 2*y)%2;
                                        break;
                                case 0x0C: // Leaves
                                        if (mapLevel[x-1][y] != 0x0C && mapLevel[x][y-1] != 0x0C)
                                                tileId += 1;
                                        else if (mapLevel[x+1][y] != 0x0C && mapLevel[x][y-1] != 0x0C)
                                                tileId += 2;
                                        break;
                                default:
                                        break;
                                }

                                sf::Sprite temp = m_tiles[tileId];
                                temp.setPosition(x*16, y*16);
                                if (layerBrightness != 0xFF)
                                        temp.setColor(sf::Color(layerBrightness, layerBrightness, layerBrightness));

                                window.draw(temp);
                        }
                }
        }
 

2
Window / SFML 2.1 on Mac - Using sf::Mouse::isButtonPressed crashes app
« on: August 16, 2013, 10:59:05 am »
Anytime sf::Mouse::isButtonPressed is used, it caused the application to crash. Using GDB to check the error, I get this:
Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: 13 at address: 0x0000000000000000
0x00007fff969cd310 in IOHIDElementGetDevice ()
(gdb) bt
#0  0x00007fff969cd310 in IOHIDElementGetDevice ()
#1  0x000000010004cbd1 in sf::priv::HIDInputManager::isMouseButtonPressed ()
#2  0x000000010004c7e7 in sf::priv::InputImpl::isMouseButtonPressed ()
#3  0x00000001000486f9 in sf::Mouse::isButtonPressed ()
#4  0x0000000100006285 in main ()

I'm using SFML 2.1 on Mac OS X 10.8.4.

Pages: [1]
anything