Hi guys
I have a 32x32 texture in one of my texture packs and I would like to repeat it horizontally and vertically, to fill the screen.
I've had a look at various code snippets on the forum, but nothing seems to be working for me.
Could someone show me the correct way to write this up, please
Thank you in advance!
Comments
Thank you for your reply - I've tried, but I can seem to get the right syntax for setting up the texture using a texture pack.
I can make this work with a single image, but not using a texture pack.
Sorry, the code I posted above is the code I 'know' how to write - using a single image. This works fine.
I can't however get it working, when pulling the image out from a texture pack. Nothing I've tried works.
EDIT: This can be done with shaders, would it be worth it to add two more shaders to gideros core to handle this ?
Thanks for the replies!
How would you guys go about handling this ...
Is it better to have a bunch of small 32x32 images for use as repeated backgrounds - separate from the levels texture pack - meaning the level will have to load a texture pack and another small image.
OR
Having a large background image, but as a part of the levels texture pack - this time the level only has to load the texture pack (which will be bigger in dimensions).
Which is the better, more efficient way to do it?
Any chance you could show me a little snippet of how this is done. I've had a look around the forums and can't seem to get it right.
Thank you very much in advance!
1. Create a sprite, with the texture pack just like you usually create it, don't add to stage
2. Create a RenderTarget with a size of that sprite
3. Then do this:
renderObject:clear(0,0)
renderObject:draw(yourCreatedSprite)
There, you can use that renderObject just like texture, so you can use it like this:
block:setFillStyle(Shape.TEXTURE, renderObject)
http://www.indiedb.com/tutorials/clipping-in-gideros-with-rendertarget
it should be useful, although the illustrated use case is not the one you are looking for.
Fragmenter - animated loop machine and IKONOMIKON - the memory game
RenderTarget.new() does not seem to support the options table so it can't be set to repeat from what I can see.
It seems like the only way to do this, is to use an image separate from the texture pack?
In this case, would you recommend ...
A small 32x32 image for use as a repeated background - separate from the levels texture pack - meaning the level will have to load a texture pack and another small image.
OR
Having a large background image, but as a part of the levels texture pack - this time the level only has to load the texture pack (which will be bigger in dimensions).
Which would be faster / more efficient?
How about mesh:
Thank you heaps for the snippet! I however don't really understand where the texture atlas is being setup.
@antix - it looks like this line is pulling the texture ...
I tried replacing the line with ...
Thank you again for your help!
fyi - I also use @2x and @4x sprite sheets
One day I must look at the Mesh class
I've followed your above instructions and this is what I have ...
I only get a single square on the screen
Thank you for your mesh method - I managed to get my texture to tile.
I however don't think it is taking my @2x and @4x sprite sheets into consideration, as it spits the texture out extremely tiny when @2x or @4x textures are being used.
Is this a limitation of this method?
In my programs I have my texture atlas which holds all my textures, and I have a table that describes individual regions inside the texture atlas. It's kind of like the texture pack but made manually.
Maybe I should switch to texture packs? I don't know what the benefits really are.
Anyway, I think you need to just replace the top two lines of code with..
Cool thanks for the heads up
I've tried the new way, and I can now get it working - however - there is the same problem as with the other snipped I posted about..
I don't think this works with @2x, @4x atlases.
The textures that are tiled are very tiny, and it looks like, its loading the smallest (@1x) texture when it should be displaying @4x.
Anybody know whether I'm right thinking that this method (render target) doesn't support @2x and @4x scaling variants?
Thanks again in advance!
I checked scale factor by myself, and see which @2x, or such is fit for it, and scale it myself. That is why this is not going in to my consideration...
@antix : Mesh is good... if you like playing with shader, but it have a limitation.
For example, sometime if you use renderTarget in Mesh, and draw just once, it might be not drawn directly in time, it might need timer delay. Or another way is you need to prepare mesh first in the first load, and just setTexture in the stage load.
Thank for the reply. Looks like I'm just going to keep a separate image to use as a repeated texture for now. I like using the Gideros automatic scaling, and I can't seem to get the methods above working with it.
If anybody can point out a different / better way, that would be awesome
Here is a snip of code from something I'm working on in my spare time, it repeats the texture to whatever dimensions I want.
https://deluxepixel.com