Sprite depth

Is it possible change the Z of a sprite like a 3d box? Any tricks? :cry:

You can change the Z order of any sprite (to have one sprite show above another). There is no depth axis in Gdevelop (2D is height or width), so if you want to simulate an object moving away or closer to the camera, you need to increase or decrease the scale, based on this imaginary “z” position, which you could store in a variable.

You may need to also make sure that objects with lower or larger (up to you really, whatever makes good sense in the project) “z” position get a larger zorder (so that they are displayed in front).

Of course you won’t really get 3D (you can’t see from the sides of the object, as there are no sides to be drawn) but you could scale things up and down to simulate objects passing in-front or below other objects. Even without scaling, you can simulate this by changing zorder (so that one object is drawn above or below another).

P.S. Maybe you could give some more information on what kind of idea you have? Maybe this would help get a more helpful reply than this one. :slight_smile:

Edit2: There’s actually a 3D box object in Gdevelop native mode. Only for boxes, as far as I know.

The scenario is that I have all the 3d boxes having a -250 Z and I found out that the walls of the boxes seem to overlap the sprite even when the z-order of the sprite is higher.

I found out the problem and solved it. Thanks guys. :smiley:

You can also use parallax scrolling, by having different images on different layers. Then go to actions and set a slower scrolling rate for a layer the farther the images on the layer are.

For example:

In Actions>Layers and Cameras>Effects>Camera center X position:

Modification sign:

(CameraX(“Base layer”,0))*0.9

New layer 1

This makes the objects on New layer 1 (which is farther from the front) scroll slower, faking a depth effect. (10% slower compared to the Base layer speed)