Khao
Member
I came up with a "different" way of approaching parallax scrolling this morning, one that deals with individual objects rather than backgrounds and layers. Basically, each object calculates the position it should draw itself by checking its distance to the center of the screen and its direction. Then it draws itself in that direction while multiplying the distance by a 'z' variable.
The end result is this:
Looks... a heck of a lot better than I expected to tell the truth! I can already imagine using it for a game, combining small objects with large scenery to create something that almost looks 3D, yet runs completely in 2D. Would be brilliant for a platformer with more complex backgrounds.
The one thing I'm worried about, is performance. With something around 80 objects that are doing absolutely nothing beyond calculating the spot they should be drawn at, my framerate goes from 1900 to less than 1000, which would mean it's... probably not feasible to do in a real game for every background object.
But that's where I think I could use some help. Do you guys think there's a more effective way of doing the same thing?
This is the code I'm currently using:
'z' is a variable I defined previously, and the one I change to adjust the position the object is drawn at. Depth is also set to z every step of course, so objects that are further back are drawn under the rest. I could easily just eliminate z entirely and use depth instead of it, now that I think about it.
Any ideas?
The end result is this:
Looks... a heck of a lot better than I expected to tell the truth! I can already imagine using it for a game, combining small objects with large scenery to create something that almost looks 3D, yet runs completely in 2D. Would be brilliant for a platformer with more complex backgrounds.
The one thing I'm worried about, is performance. With something around 80 objects that are doing absolutely nothing beyond calculating the spot they should be drawn at, my framerate goes from 1900 to less than 1000, which would mean it's... probably not feasible to do in a real game for every background object.
But that's where I think I could use some help. Do you guys think there's a more effective way of doing the same thing?
This is the code I'm currently using:
Code:
draw_x=x+(point_distance(view_xview+640,view_yview+360,x,y)*-z)*cos(degtorad(point_direction(view_xview+640,view_yview+360,x,y)))
draw_y=y-(point_distance(view_xview+640,view_yview+360,x,y)*-z)*sin(degtorad(point_direction(view_xview+640,view_yview+360,x,y)))
draw_xscale=1-z
draw_yscale=1-z
draw_sprite_ext(sprite_index,0,draw_x,draw_y,draw_xscale,draw_yscale,image_angle,image_blend,image_alpha)
Any ideas?