Working with sprites in a 3D world (like on Super Nes)

Hello,
I’m trying to reproduce my game here in Defold, a “whack a mole” where each pest has a fixed x,y position and a varying z position.
https://pauloud.github.io/FrappHooper/
I wonder if it is possible to use sprites with x,y,z position and orientation and an accurate matrix to automaticaly transform world position into the convenient screen-position and scaling.

And I wonder if it’s possible to change a rectangular sprite into a trapezoid one (so each line hasn’t the same x-scaling)

Thanks folks

Hi!

That would be very easy to do in Defold. I would suggest cutting your trapezoid sprite into four equally sized sections (cut perpendicular to the x axis) then setting the highest up/furthest back one to a Z layer of 0, the middle ones to a Z layer of 0.25, and 0.75 and the lowest down/closest one to 1.

Make the holes in your trapezoid transparent.

Set the z position of the faces to 0.1, 0.26, and 0.76 according to what row they are in.

Should be easy!

Thanks for your reply
I didn’t consider splitting it in four, it’s a good idea

I’m not sure to understand what you mean about holes, do you speak about the black holes for the maules, or the white space around ? Should a black hole of the nearest row be attached (in the scene graphe) to the Z=1.0 or the Z=0.75 trapezoid part ?

And if I had a rectangular sprite and I would like to make it non-rectangular at runtime in Defold (or the inverse : trapezoid non-rectangular to rectangular) would it be possible (with a camera or other stuff) ?

Thanks again

I ping you, to be sure you see my above reply,
Sorry if it bothers you.

@ramoneur the alternative to using sprites is to use model or mesh components to get correct perspective correction. There is some discussion about this here: Perpective behavior incoherence - #4 by Dragosha

1 Like

Delete the black holes. Make them transparent.

You can do this very easily by using a 3D camera and perspective (and indeed with meshes and models, if you want to make things really complicated!), but I would suggest first you try the 2D method with Z-layer adjustment first!

Ok thank you both, I’ll tell you what option I’ll have picked

Let us know if you need any more help and show us the final project!

I paused the project, to resume it I would like to do it like this :
Using 2d sprites give each object an x,y,z varying world-position and have the render like this : the y screen-position is a function of y and z game-position
the object is resized depending how it z world-position is
I didn’t find how doing it
Hoping someone could give me the solution
Thanks

A feasible solution I considered : having a x,y,z “world-position” properties but the game engine ignore it’s related to position and I use a regular script to transform this x,y,z position into the screen position and scaling. But I don’t find it very elegant, easy to use and optimized, since computations are made by the CPU and not the GPU

EDIT : I reopened the code, the solution I’ve chosen was to manually create 9 game objects for the 9 holes, I was a bit sad about doing it this way but it works

Ok here is the game, the same link as the old version (the sound is currently loud for the joke, it will probably change in the next days
FrappHooper 2.0

3 Likes

Amazing game. Need part 2