Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Repeat/scroll texture in a surface in directx


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 Black Knight 81   Members   -  Reputation: 109

Like
0Likes
Like

Posted 10 February 2014 - 03:36 PM

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:

StoneTile.png

 

Say I want to scroll it like this:

StoneTile2.png

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

StoneTile3.png

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:

StoneTile4.png

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.



Sponsor:

#2 Black Knight 81   Members   -  Reputation: 109

Like
1Likes
Like

Posted 12 February 2014 - 12:59 AM

Solved.

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)
    Else
        ParallaxOffsetX = MicroMod2(-ScrollXValue, ParallaxUVSize)
    End If
    If ScrollYValue > 0 Then
        ParallaxOffsetY = MicroMod2(ScrollYValue, ParallaxUVSize)
    Else
        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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS