growing a shadow

L

Latch

Guest
I'm dropping an item from the sky and trying to draw the shadow at the point where it will land, as the object gets closer I want the shadow to grow but I cant get my head around the math.

I have a dropx and a dropy that are the X/y coords of where the item will land, this is where the shadow starts, I then scale the shadow to 0.1 and plan to increase it to its default size (1) when the item lands. As the object gets closer to the mark it should increase in size but, as the distance is shrinking and i want the scale to grow I just don't know what kind of formula/function I'm looking for here. Anyone have experience with this that can help?
 
A

Amnglenathir

Guest
create item event:
distance_start=distance_to_point(dropx,dropy)
step event:
shadow_size=abs((distance_to_point(dropx,dropy)/distance_start)-1)


That makes sense in my mind. I haven't tested it but it should work. When you are drawing the shadow you can multiply shadow_size by whatever until you find what size you desire.
 

rIKmAN

Member
You need to check the y-position of the object as it falls, and then normalize this into a value between 0-1 which you can then apply to your shadow object scale to make it grow as the object falls.

Create Event
Code:
// set the start / min / max scales for our object
scale = 1.0
minScale = 0.2
maxScale = 1.0

// set the screen area (y) to scale between (scaling only happens between these y values)
minScaleArea = 200
maxScaleArea = room_height - 300
Step Event
Code:
// position object at mouse x/y
x = mouse_x
y = mouse_y

// calculate the scale of the object
scale = minScale + (y - minScaleArea) * (maxScale - minScale) / (room_height - maxScaleArea)

// lock the scale value so it doesn't go outside of wanted min/max values
if scale < minScale then scale = minScale
if scale > maxScale then scale = maxScale
Draw Event
Code:
// draw the sprite at mouse x/y with correct scale
draw_sprite_ext(sprite_index, 0, mouse_x, mouse_y, scale, scale, 0, c_white, 1)

// draw scale value as text
draw_text(x, y + 40, "scale: " + string(scale))
I made a .gmez and uploaded it so you can see it working - download here - just create a blank project and Import it from the File menu.

There may be built in GM ways to do this, but I'm a coder so do things a bit old skool :)

edit: @Amnglenathir is using the GM functions I mentioned may also work.
 
Last edited:
Top