Advertisement Jump to content
Sign in to follow this  
Black Knight 81

Repeat/scroll texture in a surface in directx

This topic is 1804 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Is there a way to repeat/scroll a part of a texture in a loaded surface?

Ex: I got a tile-system 64x64 that got all tiles in one large surface image 2048x2048.


I set up the tiles tristrip using this function in visual basic:

Private Sub Tile_GetRect(bytTileNumber As Integer, ByRef lngTileX As Single, ByRef lngTileY As Single, TileImgWidth As Integer, TileImgHeight As Integer, TileInXYRow As Single, TileWidth As Single, TileHeight As Single, Optional ColorValue1 As Long = &HFFFFFFFF, Optional ColorValue2 As Long = &HFFFFFFFF, Optional ColorValue3 As Long = &HFFFFFFFF, Optional ColorValue4 As Long = &HFFFFFFFF)
    Dim XRow As Single, YRow As Single, CalcCof As Single, X2Row As Single, Y2Row As Single
    ' Calc Y Row cof (X row is the same)
    ' TILE_HEIGHT = 64
    ' theHeightOfImage = 2048
    ' TileInYRow = TILE_HEIGHT / theHeightOfImage

    ' The tiles must have x=y grids if it has 4 tiles on the y axis it must have 4 tiles on the x axis
    CalcCof = TileInXYRow * bytTileNumber '1
    XRow = Int(CalcCof) '1
    YRow = (CalcCof - XRow) + gArtifactLines '0
    XRow = (XRow * TileInXYRow) + gArtifactLines '0.5
    X2Row = (XRow + TileInXYRow) - gArtifactLines '1
    Y2Row = (YRow + TileInXYRow) - gArtifactLines '0.5
    ' Set up Rect
    TriStrip(0) = CreateTLVertex(lngTileX, lngTileY, 0, 1, ColorValue1, 0, XRow, YRow)
    TriStrip(1) = CreateTLVertex(lngTileX + TileWidth, lngTileY, 0, 1, ColorValue2, 0, X2Row, YRow)
    TriStrip(2) = CreateTLVertex(lngTileX, lngTileY + TileHeight, 0, 1, ColorValue3, 0, XRow, Y2Row)
    TriStrip(3) = CreateTLVertex(lngTileX + TileWidth, lngTileY + TileHeight, 0, 1, ColorValue4, 0, X2Row, Y2Row)
End Sub

This function just calculates the position of the tilenumber. Ex I want tile number 5 and I get the tiles UV pos in the surface. This works well.


But I now want to be able to scroll it inside the created vertex area. Ex:

My tile is drawn like this:



Say I want to scroll it like this:


Now parts of the texture is black. But I want it to wrap like this (added some black lines just to make it clear):


Is this possible to do with one draw? Or do I need to draw 4 tiles and cut and fit them to the right place? I know I can create a repeat area like this:


And just calc a UV pos 64x64 tile in this surface and when I scroll and reach one end I just add or substract 64 from the currect UV pos to make it repeat. But If I do this I will end up with a 4096x4096 surface.


Why do I want to do this. I want to make a parallax image so when the player moves the tiles scrolls inside a drawn and moving vertex area.

Share this post

Link to post
Share on other sites


All my tiles is not used for parallax scroll. So I only created a repeat area for those tiles in the 2048x2048 surface. I now call this sub:

Public Sub Tile_ParallaxValue_OnlyOffset(ScrollXValue As Single, ScrollYValue As Single, ParallaxUVSize As Single, ParallaxOffsetX As Single, ParallaxOffsetY As Single)
    ' Calc Procent of the scale
    If ScrollXValue > 0 Then
        ParallaxOffsetX = MicroMod2(ScrollXValue, ParallaxUVSize)
        ParallaxOffsetX = MicroMod2(-ScrollXValue, ParallaxUVSize)
    End If
    If ScrollYValue > 0 Then
        ParallaxOffsetY = MicroMod2(ScrollYValue, ParallaxUVSize)
        ParallaxOffsetY = MicroMod2(-ScrollYValue, ParallaxUVSize)
    End If
End Sub

ParallaxUVSize = u2-u1 on one tile in my tilesystem.

scrollvalueX = Tile_ParallaxUVSize * (PlayerXPos * 0.001)

All I need to do is to change the "0.001" and make the background scoll in a different speed.


Sorry if I bothered anyone. Answering my own question.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!