|
Sprites and Layers
#474553
10/22/18 17:16
10/22/18 17:16
|
Joined: Aug 2014
Posts: 57
Yking
OP
Junior Member
|
OP
Junior Member
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 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: rayp]
#474557
10/22/18 18:27
10/22/18 18:27
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
Serious User
|
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
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
Yking
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2014
Posts: 57
|
Thanks for the answers so far 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: rayp]
#474576
10/23/18 13:57
10/23/18 13:57
|
Joined: Aug 2014
Posts: 57
Yking
OP
Junior Member
|
OP
Junior Member
Joined: Aug 2014
Posts: 57
|
Thank you both again for your help, I really, really appreciate it! 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
|
|
|
|