GMLscripts.com

Discuss and collaborate on GML scripts
Invert

You are not logged in.

#2 Re: GML Code Help » Drawing one view in different places ? » 2014-03-18 12:10:13

xot wrote:

Both problems can be addressed with this resource management script:

http://www.gmlscripts.com/script/map_sprites

...

this method worked out very well, but when I'm using this I found a problem:
in a keyboard press event I use the code:

Expandwith (all){
    // Change the current sprite to its alternate version, if any
    if (ds_map_exists(global.mapSpritesColor, sprite_index))
    {
        sprite_index = ds_map_find_value(global.mapSpritesColor, sprite_index);
    }
    else if (ds_map_exists(global.mapSpritesBW, sprite_index))
    {
        sprite_index = ds_map_find_value(global.mapSpritesBW, sprite_index);
    }
}

but it came out that all of my objects are having a square collision box. It seems that when I'm desaturating the sprites, I also need to copy the original mask information to the new b&w sprites? One method I found is to set every object's mask in the object properties independently, but that's a little complicated and I need some simpler scripts.
I tried this piece of code but it didn't work out:

Expandif mask_index == -1
{
       mask_index = sprite_index;
}

so I guess I totally lost my mask data after sprite_desaturate, is there a method to maintain the mask? Thanks in advance smile !

#3 Re: GML Code Help » Drawing one view in different places ? » 2014-03-06 03:08:17

xot wrote:

The idea behind the method is to use the original sprite's brightness as an alpha channel for a new solid white sprite. This is done with a call to sprite_set_alpha_from_sprite(). The bright areas from the original sprite make the respective areas of the new white sprite opaque. Likewise, the dark areas make the respective areas of the new white sprite transparent. When this semitransparent white sprite is drawn on top of black, it results in a grayscale image.

The only way to manipulate alpha channels like this is to use sprite_set_alpha_from_sprite(). Color/alpha information cannot otherwise be communicated between channels, using blending mode for instance. Unfortunately, this requires the creation of sprites and creating large sprites is quite slow. Doing this every step is generally impractical unless you are working in a very low resolution, but it is worth a try. Hopefully, I've given you enough info to help you adjust your code.

There are some other options for GM8. One is maintain duplicate B&W sprites and switch between them and the normal sprites as needed. They could be generated once at the start of the game and used thereafter.

Another option is shaders. Shaders can do this sort of effect quite efficiently. If you don't mind using a GEX/DLL, ps1.4 shaders can be used in GM8. Unfortunately, it does not work with GM8.1. Also, the shaders must be written in assembly, not HLSL. I have some experience with this and can help you.

http://gmc.yoyogames.com/index.php?showtopic=492876

If I took the first method, how can I cycle through all the sprites in my game ? And if I want to switch between the sprites, the method I came up with is using execute_string, will that slow the game down too?

#4 Re: GML Code Help » Drawing one view in different places ? » 2014-02-28 12:33:18

xot wrote:

You can draw the surface in the draw event but you need to make sure it is not drawn when you call screen_redraw(). You could use a variable to control that or use instance visibility like I showed earlier. That's a method I've used in the past.

However, the way I do it in the example is less complicated, faster, and generally works well in GM8. This method would not work with GameMaker: Studio.

can I draw the screen in a black & white style ?
I saw there was a script called sprite_desaturate to desaturate the sprite, it worked out well for sprites. But when I want to desaturate all the instances on the screen, it became really slow to process. So I wonder if I can desaturate the screen instead of desaturate the separate sprites. I tried to play with the code in sprite_desaturate in order to desaturate the screen, but it didn't turn out well (honestly I didn't understand the method in that script sad ). I revised some of the code in the Begin Step Event:

Expandif (surface_exists(surfScreen)){
    surface_set_target(surfScreen);
    draw_clear_alpha(c_white,1);
    tempsprite = sprite_create_from_surface(surfScreen,0,0,view_wview[0],view_hview[0],0,0,0,0);
    draw_clear_alpha(c_black,1);
    draw_sprite(tempsprite,i,0,0);
    draw_set_blend_mode(bm_add);
    draw_rectangle_color(0,0,view_wview[0],view_hview[0],c_black,c_black,c_black,c_black,false);
    newsprite = sprite_create_from_surface(surfScreen,0,0,view_wview[0],view_hview[0],0,0,0,0);
    draw_sprite(newsprite,-1,0,0);
    surface_reset_target();
    draw_surface(surfScreen,0,0);
//    screen_refresh();
}
else{
    surfScreen = surface_create(view_wview[0], view_hview[0]);
}

but sadly I got nothing. Could you help me with it?

#5 Re: GML Code Help » Drawing one view in different places ? » 2013-12-25 11:04:05

xot wrote:

This is how I would do it, using a method like ChevyRay's. It is efficient and the object can be inserted into any project without changing anything else.

https://www.dropbox.com/s/ygl0k19ejbksd … e.gmk?dl=0

this is amazing !

maybe what I'm doing wrong is drawing the surface in the draw event , not in the Begin Step event .. thanks xot! smile

#6 Re: GML Code Help » Drawing one view in different places ? » 2013-12-25 00:40:55

xot wrote:

If you don't want to have your draw event interfering with your call to screen_redraw(), you can make the object invisible before calling it.

Expandsurface_set_target(global.surf);
draw_clear_alpha(c_black,1);
visible = false;
screen_redraw(); //capture the screen
visible = true;
surface_reset_target();

However, I'm not sure I understand the question.

There are also ways to capture a screen to a surface without using screen_redraw(). That might work better for you.

This tutorial by ChevyRay explains one method I've had success with:
http://forums.tigsource.com/index.php?t … 9#msg86809

The important parts are:
1. In the End Step event, use surface_set_target().
2. In the Begin Step event, use surface_reset_target(), draw the surface to the display, and use screen_refresh() to update the window.

A similar method from YellowAfterlife is demonstrated here:
http://yal.cc/gamemaker-automatic-pixel … w-scaling/

thx for the solution ! I'll try it first

0JGfXfH.png

the effect I want to achieve is like this.

one on the left is what actually happens on the screen

the right one is what shows on the screen .

Anyway , I'll try your method first smile

EDIT: maybe you didn't understand me sad , and my code is really messy.

what I want to do is draw the whole screen on one surface, and use draw_surface_tiled_ext to fill that surface to the whole screen.

but I don't know how to disable the drawing on screen, without interfering other objects.

#7 GML Code Help » Drawing one view in different places ? » 2013-12-23 02:57:11

Nikaple
Replies: 12

I'm using a GM8 pro version and want to create a cool effect that can draw a lot of copies of one view simultaneously.
GM provides 8 views but I'm not satisfied with that (maybe 16 or more).
so I want to use a surface to solve that problem. Here's what I got so far(only 4 copies):
Create Event:

Expandglobal.surf=surface_create(room_width,room_height);

End Step Event:

Expandif(!surface_exists(global.surf)){
  global.surf=surface_create(room_width,room_height);
}
surface_set_target(global.surf); 
draw_clear_alpha(c_black,1);
screen_redraw(); //capture the screen
surface_reset_target();

Draw Event:

Expandif(surface_exists(global.surf)){
   draw_surface_ext(global.surf,0,0,0.5,0.5,0,c_white,1)
   draw_surface_ext(global.surf,room_width/2,0,0.5,0.5,0,c_white,1)
   draw_surface_ext(global.surf,0,room_height/2,0.5,0.5,0,c_white,1)
   draw_surface_ext(global.surf,room_width/2,room_height/2,0.5,0.5,0,c_white,1)
//this can be changed to the draw_surface_tiled_ext function to adapt for more
}

and my views become messy. So I know probably I shouldn't draw on the screen anymore to avoid the repeating capturing the screen,
but if I stop drawing on the screen, screen_redraw() can't capture my screen anymore. I'm in such a paradox and don't know what to do..

I'm not very good in English , hope that you can understand me smile

Any help will be appreciated!

Board footer

Powered by FluxBB