You basically transform texture coordinates by modifying Texture.repeat and Texture.offset. You just need to know some properties about your sprite sheet e.g. how many images it contains and the respective dimensions. Check out the following live demo to see this approach in action:
how can i loop tilesets, if i have tile of 3x3 (3rows and 3 cols) i want to loop like in javascript from left top to bottom right ,your exemple i can only loop by x axis but not y
Yes ,that works , but it displays not in original width and height,also positioning on screen does not works,i tried spriteSheet.position.set(200,400) didn’t worked https://jsfiddle.net/1x94m3sy/
Um, I’m not sure it makes sense to replicate the logic from your fiddle by just transforming texture coordinates. As far as I can see, your fiddle performs multiple calls to CanvasRenderingContext2D.drawImage() per frame in order to produce the final result of the animated texture.
Have you considered to use THREE.CanvasTexture in order to wrap the final/target canvas element into a texture object and render it on a plane? In this way, you can reuse most of the existing code. Using a canvas element as a data source of a texture is also demonstrated in this example:
" As far as I can see, your fiddle performs multiple calls to CanvasRenderingContext2D.drawImage() per frame in order to produce the final result of the animated texture."
yes it is because of animation several sprites, i 'm updating canvas at each frame
well i think the best way to explain you what i want to build is a 2d game in 3d world pixelworld, my pure javascript performes about 60 frames per second,but it will go down if i will add more sprites on it.
That’s i want give a try with ThreeJS !
as i saw some examples the thing is that i cannnot draw sprite directly in canvas ?, i need to create a material put a sprite on it then create a Geometry and finally create a Mesh
like here: var mesh1 = new THREE.Mesh( geometry, material );
the approach is like i want create a loop that loops through mapArray (example that i linked you above) and position the sprite based on array length of row and col to the Screen(canvas) position
i found this example https://github.com/mrdoob/three.js/blob/master/examples/webgl_raycast_sprite.html looks like position its easy, but maybe it’s not suited for best performance?
Hey, concerning your exemple here Edit fiddle - JSFiddle - Code Playground , how can i choose the index to start and end of the sprite ? like i want to animate from 2s index to 4th etc
The code of the fiddle is too simple in order to support such requirements. You need a more advanced approach to make things more configurable. Unfortunately, I don’t have time to develop a solution for you. Maybe you find something useful in this thread: