GMS 2.3+ sprite_create_from_surface not working as expected...

FoxyOfJungle

Kazan Games
Hello!

I have a question:
Are sprite_create_from_surface() and sprite_get_texture() working normally?
Because they're giving me incorrect proportions in my texture...

See:

1 - This works:
GML:
ftr_from_surface = view_get_surface(view_number);
ftr_from_surface_tex = surface_get_texture(ftr_from_surface);



2 - Doesn't works:
GML:
ftr_from_surface = view_get_surface(view_number);
ftr_from_surface_tex = sprite_get_texture(sprite_create_from_surface(ftr_from_surface, 0, 0, surface_get_width(ftr_from_surface), surface_get_height(ftr_from_surface), false, false, 0, 0), 0);

Notes:
  • Above, the sprite is created with the wrong proportions...
  • The surface and texture are created only once.

This texture is then received by the shader, then rendered to the screen in the same way as the first method.


view_get_surface():
GML:
function view_get_surface(view) {
    var _w = view_wport[view];
    var _h = view_hport[view];
    var _s = surface_create(_w, _h);
    surface_copy_part_fixed(_s, 0, 0, application_surface, view_xport[view], view_yport[view], _w, _h);
    return _s;
}
Thanks for listening.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Have you tried creating the sprite first then using it in the texture function? EG:
GML:
ftr_from_surface = view_get_surface(view_number);
var _w = surface_get_width(ftr_from_surface);
var _h = surface_get_height(ftr_from_surface);
var _spr = sprite_create_from_surface(ftr_from_surface, 0, 0, _w, _h, false, false, 0, 0);
ftr_from_surface_tex = sprite_get_texture(_spr, 0);
It could be something in the order in which GM does things internally that is the issue here... Also, add a breakpoint using BOTH methods you describe, then check what the actual texture being used in both cases is like... The debugger has a textures section, so run the code, then refresh the texture tab and see what the sprite and surface textures actually look like and what their size is. That might help give a clue as to what is going on too.


PS: I hope you're also deleting the surface you return with the view_get_surface() function somewhere otherwise you'll have a memory leak... ;)
 

FoxyOfJungle

Kazan Games
Have you tried creating the sprite first then using it in the texture function? EG:
GML:
ftr_from_surface = view_get_surface(view_number);
var _w = surface_get_width(ftr_from_surface);
var _h = surface_get_height(ftr_from_surface);
var _spr = sprite_create_from_surface(ftr_from_surface, 0, 0, _w, _h, false, false, 0, 0);
ftr_from_surface_tex = sprite_get_texture(_spr, 0);
It could be something in the order in which GM does things internally that is the issue here... Also, add a breakpoint using BOTH methods you describe, then check what the actual texture being used in both cases is like... The debugger has a textures section, so run the code, then refresh the texture tab and see what the sprite and surface textures actually look like and what their size is. That might help give a clue as to what is going on too.


PS: I hope you're also deleting the surface you return with the view_get_surface() function somewhere otherwise you'll have a memory leak... ;)
I will try to do this and come here with the results. Thanks!
Thank you for the advice! I'm actually deleting the surface in the destroy event šŸ™‚


Hey! I've been looking for that lightning effect. Do you have any tutorials for that? Please tell me. Thanks
Oh, this is not a lighting system, it's a transitions asset that I'm making and will make available on YYG Marketplace. However, follow me that in the future I will make a lighting system from this. It uses shaders for best results :)
 

FoxyOfJungle

Kazan Games
Have you tried creating the sprite first then using it in the texture function? EG:
GML:
ftr_from_surface = view_get_surface(view_number);
var _w = surface_get_width(ftr_from_surface);
var _h = surface_get_height(ftr_from_surface);
var _spr = sprite_create_from_surface(ftr_from_surface, 0, 0, _w, _h, false, false, 0, 0);
ftr_from_surface_tex = sprite_get_texture(_spr, 0);
It could be something in the order in which GM does things internally that is the issue here... Also, add a breakpoint using BOTH methods you describe, then check what the actual texture being used in both cases is like... The debugger has a textures section, so run the code, then refresh the texture tab and see what the sprite and surface textures actually look like and what their size is. That might help give a clue as to what is going on too.


PS: I hope you're also deleting the surface you return with the view_get_surface() function somewhere otherwise you'll have a memory leak... ;)
Unfortunately it didn't work :(



Well... I was trying to do this because sprites are not volatile if I resize the window. Do you know how I would backup a surface and prevent me from losing its contents?
 
Top