How do you tile a texture in a Sprite?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By MikeyZman

Not sure if what Im trying is legal. I have a long collisionshape2D that is a platform, and I’d like for it to look like a brick wall (think like mario bros platforms). I DL a brick texture (jpg) and assigned it to a sprite that is the same size as the collisionshape2D. I assumed that Godot would tile the texture repeatedly and I could size it until it spanned the sprite length, but it won’t and Im not even sure what Im trying is legal. My fix is several smaller square sprites (and appropriately scaled texture) that span the long collisionshape2D. To me this seems inefficient - or maybe it’s not? Thanks for help in Advance. below is my texture import log:

“vram_texture”: false


dest_files=[ “res://.import/stone2.jpg-648ba8c1b0479e62cefbf8c964439136.stex” ]



:bust_in_silhouette: Reply From: njamster

It’s probably easier to use a TextureRect for this:

Using A TextureRect

  1. Create a TextureRect-node
  2. Assign your image as its texture
  3. Set expand to true
  4. Set strech_mode to STRETCH_TILE / 2
  5. Set rect_size to the dimensions you wish for

That said, if it has to be a Sprite, here you go:

Using A Sprite

  1. Select your image in the “FileSystem”-Tab
  2. Switch over to the “Import”-Tab (next to the “Scene”-Tab)
  3. Set “Repeat” to “Enabled” and click “Reimport” (at the bottom)
  4. Create a Sprite-node
  5. Assign your image as its texture
  6. Set region_enabled to true
  7. Set region_rect to the dimensions you wish for

Thanks so much for the help. I am using 3.2 so I didn’t have the property selections that you indicated.

I did find a solution, however. My platform is 64pix deep x whatever length, Im going in even grid increments (64 pix reticules), so I resized my main texture to 64x64, created a TextureRect that was 64 pix thick and 64 x N blocks long and set the stretch mode to tile. That repeated the pattern. It works, and Ive learned several things just with struggling with this.

I used to make maps for Counter Strike years ago and I was used to being able to apply a texture to a polygon and size it in the editor, so I thought that would apply here. I’m sure it does and I am having success but maybe what I remember with mapping tools is not the same implementation here. Just gotta learn!

MikeyZman | 2020-02-22 19:29

I’m using 3.2 as well. I don’t know, what exactly you’re referring to by “property selections” here, but you’re probably just looking for it in the wrong place:

  • The “FileSystem”-Tab is by default in the lower-left of the window
  • The “Import”-Tab is by default in the upper-left of the window
  • Everything else is done in the “Inspector”, which is by default on the right side

Your solution equals the one I proposed under “Using A TextureRect”. What you describe from your Counter Strike days is possible by following the steps 1-3 from my second solution (titled “Using A Sprite”), then creating a Polygon2D-node and setting it’s texture-property to that image. It will fill out the Polygon completely (by repeating itself) and adapt accordingly, when you resize the Polygon later on.

njamster | 2020-02-24 13:25