How to cut a texture? (parallax inside a box)


#1

How to cut a texture?
I wanted to make a parallax inside a square, I have a Gameobject with several sprites, the problem is that each sprite is full, and I want to show only one part, and then move it and show the remain sprite, (moving it from left to right from example), can this be done?


#2

You can do it with stencil in ui.
For sprite - either shader or the trick with render target.


#3

I dont know what are you talking about, can you explain more noob friendly? thanks


#4

Simplest way - in UI, just put one node into another and setup stencil mask so you can move the inner node and see only part of it.
Or you can render sprite into custom render target and then render quad\sprite with resulted texture on main render target.


#5

I try the ui mode, its hard to understand how render works…
Now, how can I move in runtime the node inside the first node? I will need to have one node followed by another, no? thanks

I try gui.get_node(“box1/box2”) but doesnt work


#6

gui.set_position(node, vector3) will move a node. Check the API reference: https://www.defold.com/ref/gui/


#7

Ok, I thought I need to pass the parent.

and for do the same with GameObjects?


#8

Discussed here: How to mask/clipping a sprite?