GML [SOLVED] drawing shadows

DaDonMike

Member
hi, i have a really hard one to work out.. for me anyway..

i have a tree and its set to its own x & y in the room.

for the tree shadow i'm redrawing the tree and setting alpha to 0.5 and set it to black and to the trees x & y.

i have a player with a torch witch is top down view and the whole rooms black but where the torch is.

i want to draw the shadow where the torch is shining at the tree.. i'm using a virtual joystick witch sets a value from 0 to 360 depending on witch way its pointing. i'm struggling to do the math so it only turns to the opposite side everytime the player is in a different location. iv looked online and cant seem to find what i'm looking for. and i'm using surfaces. but id rather it done by the way i said above. thanks
 
C

CptChuckles

Guest
The shadow direction will be the same as the direction from the player to the tree.
Code:
ShadowAngle = point_direction(player.x,player.y, tree.x,tree.y);
 

DaDonMike

Member
hi, thanks for the reply, i have a script called "scr_shadow" and inside it is this..
Code:
draw_sprite_ext(sprite_index,-1,x-argument0,y-argument1,image_xscale,image_yscale,image_angle,c_black,argument2);
draw_sprite(sprite_index,-1,x,y)
how would i put that in the code with its own x and y? thanks
 

Kahrabaa

Member
Code:
ShadowAngle = point_direction(player.x,player.y, x,y);
var lx=lengthdir_x( argument0, ShadowAngle);
var ly=lengthdir_y( argument0, ShadowAngle);
draw_sprite_ext(sprite_index,-1,x+lx,y+ly,image_xscale,image_yscale,image_angle,c_black,argument1);
draw_sprite(sprite_index,-1,x,y)
Edit: argument0 would be the distance from the tree
 

DaDonMike

Member
Code:
ShadowAngle = point_direction(player.x,player.y, x,y);
var lx=lengthdir_x( argument0, ShadowAngle);
var ly=lengthdir_y( argument0, ShadowAngle);
draw_sprite_ext(sprite_index,-1,x+lx,y+ly,image_xscale,image_yscale,image_angle,c_black,argument1);
draw_sprite(sprite_index,-1,x,y)
Edit: argument0 would be the distance from the tree
This worked thanks!
 
Top