Gamestudio Links
Zorro Links
Newest Posts
Blobsculptor tools and objects download here
by NeoDumont. 03/28/24 03:01
Issue with Multi-Core WFO Training
by aliswee. 03/24/24 20:20
Why Zorro supports up to 72 cores?
by Edgar_Herrera. 03/23/24 21:41
Zorro Trader GPT
by TipmyPip. 03/06/24 09:27
VSCode instead of SED
by 3run. 03/01/24 19:06
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (Quad, aliswee), 835 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
sakolin, rajesh7827, juergen_wue, NITRO_FOREVER, jack0roses
19043 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Sprites and Layers #474553
10/22/18 17:16
10/22/18 17:16
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
A while ago I asked for help on the best solution for a tile based 2D game in another thread here and I have been trying around many different things since then.

However, there is a basic problem that I need to solve aswell, something that I am not sure on how to approach.

I have two sprites that are created in a level.
At positions vector(-100, 0, 0) and vector(100, 0, 0)
Simply: One is left and one is right, the Z is the same

Is it possible to have one Sprite always on top, no matter what the Z is? Layers, for example would be cool, but I did not find anything that worked.
The moving tree here, should always stay in front of the other one.

(The different Y's of the trees are just for making it more clear)

If I would change the Z,
then moving the camera causes a kind of "parallax scrolling" which I don't want.

Is there any solution for this?
Either layering the sprites somehow or
getting rid of the "parallax scrolling" when Z is different?

Yours Yking

Quote:

My test code:

///////////////////////////////
#include <acknex.h>
#include <default.c>

///////////////////////////////
function main()
{

video_window(NULL,NULL,NULL,"TEST");
vec_set(sky_color,vector(0,0,0));
level_load(NULL);
camera.pan = 90;
camera.tilt = 90;
camera.x = 0;
camera.y = 0;
camera.z = -700;
camera.ambient = 100;

ENTITY* sprite_a = ent_create("data/textures/sprites/test.tga", vector(-100, 0, 0), NULL);
sprite_a.tilt = -90;
sprite_a.pan = -90;


ENTITY* sprite_b = ent_create("data/textures/sprites/test.tga", vector(100, 0, 0), NULL);
sprite_b.tilt = -90;
sprite_b.pan = -90;


while(1)
{
//Movement
if (key_w == 1) {while(key_w ==1){wait(time_step*300);sprite_b.y -= 5; }}
if (key_s == 1) {while(key_s ==1){wait(time_step*300);sprite_b.y += 5; }}
if (key_a == 1) {while(key_a ==1){wait(time_step*300);sprite_b.x -= 5; }}
if (key_d == 1) {while(key_d ==1){wait(time_step*300);sprite_b.x += 5; }}
wait(1);
}


}


Re: Sprites and Layers [Re: Yking] #474554
10/22/18 17:38
10/22/18 17:38
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Seting overlay flag or using a material might help.

When iam at home i can provide example material, but this is around here or on the wiki if u wanna search now

Greets

Last edited by rayp; 10/22/18 17:39.

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Sprites and Layers [Re: rayp] #474557
10/22/18 18:27
10/22/18 18:27
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Quote:
getting rid of the "parallax scrolling" when Z is different?


Maybe adding the 'isometric' camera flag so you can modify the sptites depth with no distortion of perpective. You may want also take a look to 'd3d_entsort'.

Re: Sprites and Layers [Re: txesmi] #474564
10/22/18 21:07
10/22/18 21:07
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Thanks for the answers so far laugh

The thing that would be the best would probably be the Isometric camera, however i have tried that over and over and I cannot get it to work, I have set the flag but everything stays the same, am I missing a step?
(I tested it by changing the sprites Z and moving the camera, the flag doesn't make a difference for me)

I tried the "d3d_entsort" and none of the options seems to work either, setting it to 0 (not sorting at all) works in this case, but the moving sprites always go on top and that would mean that the player always walks "on" the trees and not under them.

I am not sure how materials work yet but I will research into it, too

Re: Sprites and Layers [Re: Yking] #474568
10/22/18 22:12
10/22/18 22:12
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
If the Problem is transparent / sorting related this may help ( old example from wiki ), if not iam sry:
Code:
MATERIAL* mat_alphatest=
{
  effect =
  "
    technique alpha_test
    {
      pass p0
      {
        zWriteEnable = true;
        alphaTestEnable = true;
        alphaBlendEnable = false;
      }
    }
  ";
}

action apply_alphatest_material(){
  my.material = mat_alphatest;
}

i just converted from wiki to lite-c. but did not test.

Greets


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Sprites and Layers [Re: Yking] #474569
10/22/18 22:44
10/22/18 22:44
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
It is hard to know what are you exactly trying. Basic 2d engines use three layers: a background, a foreground and the rest in the middle. Things that can overlap and can be overlapped by a character are normally cut in two pieces, so the down part is drawn in the background and the upper part in the foreground, been an unwalkable tile the 'connection' between both.

Re: Sprites and Layers [Re: txesmi] #474570
10/22/18 23:41
10/22/18 23:41
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
I once faked sorting in a fun/test-project 2d sidescroller using the Y+Z axis of the sprites. Player can walk up and down + left and right. Up and Down is handled via Y pos (to sort sprites) + Z pos (visual movement) of sprites.
Maybe theres a smarter solution but for me it worked ok.


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: Sprites and Layers [Re: rayp] #474576
10/23/18 13:57
10/23/18 13:57
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Thank you both again for your help,
I really, really appreciate it!

Originally Posted By: txesmi
It is hard to know what are you exactly trying.


I want to clarify it a bit better, it is hard for me to describe properly.
The Game is layered like this:


The Game is from a Top-Down Perspective
Left = -X
Right = +X
Up = -Y
Down = +Y
And Zooming out would then technically be -Z, zooming in +Z

The Background (Grey rectangle) is no problem, just a texture, and it could be exactly at vector(0,0,0)

The NPC-layer (orange rectangle) is where NPCs walk on. Basically, NPCs would need a smaller Z (perhaps vector(0,0,-10) so they don't clip into the background layer.
However, this
a) causes parallax scrolling when the camera moves, "floaty" layers
b) All NPCs on the NPC-layer all have the same Z, so they also clip into each other

Now, I understand that d3d_entsort could solve Problem b) by always making the one NPC go on top, who is closer to the camera on the Y-Axis but I can't wrap my head around the 3-dimensionals yet and changind d3d_entsort has not brought me any success.

This is way harder for me than I thought shocked

Re: Sprites and Layers [Re: Yking] #474581
10/23/18 19:11
10/23/18 19:11
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
I got it to work, and I don't really know how
The Isometric flag suddenly started working and now I can use the sprites' Z-coordinates to layer them.
No more floatiness and no was d3d_entsort needed

If I figure out what I did differently, I will add a post!

Re: Sprites and Layers [Re: Yking] #474582
10/23/18 19:45
10/23/18 19:45
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Congratulations! laugh

I would set d3d_entsort to 8 because is cheaper and fits your needs.

Re: Sprites and Layers [Re: txesmi] #474584
10/23/18 20:39
10/23/18 20:39
Joined: Aug 2014
Posts: 57
Y
Yking Offline OP
Junior Member
Yking  Offline OP
Junior Member
Y

Joined: Aug 2014
Posts: 57
Oh my god, I understand this now.

I downloaded a 30-day-trial while at university, since I didn't have my original at hand, tried the damn testcode again and it worked.
Super happy, saving the files, going home aaaand... it doesn't work.

Looking at the website:
Isometric view needs Pro-Edition and I only have Extra.
I cannot use this feature frown

Re: Sprites and Layers [Re: Yking] #474608
10/25/18 10:49
10/25/18 10:49
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I was a step away from explaining how to manage tiles with a shader. What a pity!

Page 1 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1