• 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!

SOLVED Spider strings (no not that string)

Turns out I'm not very good at this...how do I automatically draw a white line from the spider's abdomen to the bottom of the platform above it? I'm trying to make the spider look like it's hanging from the platform. I suspect I need to use a "while" loop here but don't exactly know how to set it up. Help!

spider_help.png
 
Last edited:
Yeah I know how to use draw_line_width() but my problem is calculating the distance from the spider's abdomen to the bottom of the platform.
 

Prrz

Member
Ah okay, sorry - sometimes the simplest solutions allude us so I wanted to make sure you weren't missing something obvious!

I'm guessing that the platform is made of tiles? If so, that makes it a little more complicated to calculate.

If it is a tile and you know it's draw depth you could use tile_layer_find(depth, x, y); .... Something along the lines of:
GML:
// Create
draw_line_to_tile = noone;

// Whatever event makes most sense
var depth = -1000;
for(var i = 0; i < SIZE_OF_TILE * 4; i++) { // * however many you want to check
    var tile = tile_layer_find(depth, x, y + (SIZE_OF_TILE * i));
    if(tile != -1) {
        draw_line_to_tile = tile;
        break;
    }
}


// Draw
if(draw_line_to_tile != noone) {
    draw_line(x, y, draw_line_to_tile.x, draw_line_to_tile.y);
}
I'm honestly not sure if this would work, or if it's an efficient way of doing so - but it's an idea! If anyone else could chime in, that would be great.

You might need to use tile_get_x(index); and tile_get_y(index); somewhere in here too, but I'm not sure. Worth testing out I suppose!

Of course the hacky way would be to just draw a line under the spider from its (x,y) to straight upwards and keep twiddling with the numbers until it works - but if you plan on having more than one spider, that would not be ideal.
 
Last edited:
Spectacular! I’m very glad you got it working, what code did you end up using? (In case someone else stumbled across a similar problem)
So since I do use tiles I was able to use tilemap_get_at_pixel() (tile_layer_find wasn't a function for some reason) to achieve pretty much the same approach. Code:
GML:
///"Create" event

//Spider string
var tile_layer = layer_get_id("Tiles_1");
var tilemap = layer_tilemap_get_id(tile_layer);
var tile_size = 16;

for(var i=0;i<=tile_size*8;i++) {
    var tile_found = tilemap_get_at_pixel(tilemap,x,bbox_top-i);
    //Used bbox_top since that's where the spider's abdomen is
  
    if tile_found > 0 {//"0" indicates an empty tile in my case
        wall_x = x;
        wall_y = bbox_top-i;
        break;
    }
}
Now I'm trying to figure out how to get the spider to swing whenever the player attacks it. I've already done some research on it and I think I can do it myself but if not then I'll probably make another post about it.
 
Top