• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Need help drawing a rope sprite from one point to another

smashencoo

Member
So I just need a simple rope design where a rope sprite stretches from one object to another. I tried using the draw_sprite_general function so I could use the width and rotation to have it follow the objects:

var angle;
var distance;
distance = distance_to_object(obj_Buck_Plane);
angle = point_direction(x,y,obj_Buck_Plane.x,obj_Buck_Plane.y);
draw_sprite_general(spr_rope,1,x,y,distance,sprite_height,x,y,1,1,angle,c_white,c_white,c_white,c_white,1);

But the rope isn't drawing. It is in the draw event if you are wondering. I used x and y because the object with the code is where I want it to anchor. If you can fix this code or give me something else entirely that works, it doesn't matter, either way is fine. Basically I just want to stretch a sprite from one point to another, but also rotate it in the direction of the other object, and the draw_sprite_stretched function doesn't have a rotation option. I imagine there must be a much simpler way that I don't know about. Knowing this will help a lot with all my future projects as well. Thanks.
 
General is not what you want, the ext function is what you want. The origins of the sprite should be on the left middle.
Code:
var angle;
var distance;
distance = distance_to_object(obj_Buck_Plane);
angle = point_direction(x,y,obj_Buck_Plane.x,obj_Buck_Plane.y); 
draw_sprite_ext(spr_rope,1,x,y,distance,1,angle,c_white,1);
 

FrostyCat

Redemption Seeker
var angle;
var distance;
distance = distance_to_object(obj_Buck_Plane);
angle = point_direction(x,y,obj_Buck_Plane.x,obj_Buck_Plane.y);
You are asking for "human's position" in a room full of people. This is guaranteed to end badly, for a reason that any competent GML user should know.

Use instance_nearest to get the closest instance ID, then get the distance and angle to it unless it turns out to be noone.

draw_sprite_general(spr_rope,1,x,y,distance,sprite_height,x,y,1,1,angle,c_white,c_white,c_white,c_white,1);
Extracting the area of the sprite starting from (x, y) with dimensions (distance, sprite_height) makes no sense. This too will end badly, for a reason that should be obvious if you try seeing where that region is in the sprite editor.

Use draw_sprite_ext with distance/sprite_get_width(spr_rope) as the horizontal scale. And if you still want to use draw_sprite_general, read the Manual description of what each parameter does before using it.
 
Top