Antikore
Member
I've been playing around with GMS 1.4 native networking the last days and I'm doing pretty good, but the challenge I'm facing now is so much more complicated than I've expected.
My idea is to send an small image (240 x 135) from the server to the client. As I'm doing my tests on my own computer, I just want the server to take a .png from the game's folder and the client create the same .png with another name on that folder. However, at the end the client is only creating a fully transparent 240 x 135 png file. Here is the current code after multiple changes to see what may work and what doesn't
I searched on the Internet for similar issues, but I only found a post that the issue was actually irrelevant and the solution wasn't explanatory for my issue.
using Windows 10 and GameMaker: Studio v1.4.1804
Just in case these are the buffer specs
My idea is to send an small image (240 x 135) from the server to the client. As I'm doing my tests on my own computer, I just want the server to take a .png from the game's folder and the client create the same .png with another name on that folder. However, at the end the client is only creating a fully transparent 240 x 135 png file. Here is the current code after multiple changes to see what may work and what doesn't
GML:
// Asynchronous event for networking event. This is the piece of code on network_type_connect
global.socket_to_send = async_load[? "socket"];
ds_list_add(global.players, global.socket_to_send);
var image = sprite_add("laconcha.png", 0, false, false, 0, 0);
var w = sprite_get_width(image);
var h = sprite_get_height(image);
sf = surface_create(w, h);
surface_set_target(sf);
// Looks like this is working even outside of the draw event, anyways I tried to do it on the draw event and the result is the exact same.
draw_sprite(image, 0, 0, 0);
surface_reset_target();
// Made this just in case the sprite wasn't drawing at all in the same frame.
alarm[0] = 1;
GML:
// Alarm 0 on the server controller, it writes 3 as the type of message, adds the surface
// and then sends it as a packet, then frees the surface.
if (!surface_exists(sf)) exit;
buffer_seek(global.buffer, buffer_seek_start, 0);
buffer_write(global.buffer, buffer_u8, 3);
// At this point the surface with the image is correct
// surface_save(sf, "coso.png");
buffer_get_surface(global.buffer, sf, 0, 0, 0);
network_send_packet(global.socket_to_send, global.buffer, buffer_tell(global.buffer));
surface_free(sf);
GML:
// The client packet handler, this is what executes when the packet type is 3
// as it was before established on the server
surface = surface_create(240, 135);
buffer_set_surface(buffer, surface, 0, 0, 0);
// Did this for the same reason as the alarm on the server
alarm[0] = 1;
GML:
// Client controller alarm 0, saves the surface and frees it again.
if (!surface_exists(surface)) exit;
surface_save(surface, "tonasso.png");
surface_free(surface);
using Windows 10 and GameMaker: Studio v1.4.1804
Just in case these are the buffer specs
GML:
var buffer_size = 65535;
var buffer_type = buffer_grow;
var buffer_alignment = 1;