ZFGC

Resources => Coding => Topic started by: Martijn dh on July 26, 2009, 05:54:39 pm

Title: Negative sprites in Gamemaker (round 2)
Post by: Martijn dh on July 26, 2009, 05:54:39 pm
I'm sure some of you do this blindfolded. If you could also explain the answers then that would be most appreciated.

In alttp enemies turn negative when hit. That what I want to recreate. The enemy's sprite need to turn negative through it's own draw event. White turns to black etc. But the transparent pieces should stay transparent.

The answer I got in a previous topic turned the the images grayish. Including the parts that were previously transparent.
Title: Re: Negative sprites in Gamemaker (round 2)
Post by: MG-Zero on July 26, 2009, 07:27:11 pm
Why don't you just switch to animation where the colors flash between inverted and normal colors?
Title: Re: Negative sprites in Gamemaker (round 2)
Post by: Xfixium on July 26, 2009, 08:23:50 pm
Hrmmm, most likely the reason why your getting such results is that changing the blend mode does not take the alpha into consideration. (Thus the border) Plus it's taking into consideration the colors beneath the sprite as well. (Weird grayish color) Your best bet is making a surface and drawing to that.

An example:

Object: obj_invert_colors_test;

Create Event:
Code: [Select]
Surface = surface_create(width, height);
Draw Event:
Code: [Select]
surface_set_target(Surface);

draw_clear_alpha(c_white, 0);
draw_set_color(c_white);

draw_set_blend_mode_ext(bm_inv_dest_color, bm_inv_src_color);
draw_sprite(sprite, image_index, 0, 0);
draw_set_blend_mode(bm_normal);

surface_reset_target();
draw_surface(Surface, x, y);

Destroy Event:
Code: [Select]
surface_free(Surface);
Title: Re: Negative sprites in Gamemaker (round 2)
Post by: Martijn dh on July 27, 2009, 06:14:19 pm
Thanks for the post. I was looking into surfaceses (?) so I'm glad I was on the right track.

However, I still can't get it to work. Even worse, I have no idea what I'm doing wrong. This is the same code structure I use for my pause function (excl the negative bit) and that works fine.

Here is the code I have currently put in the draw event of an enemy's sprite:
Code: [Select]
if (control_id.recovery_time > 0)
{
    // draw negative sprite
    surface_Enemy_Sprite = surface_create(sprite_width, sprite_height);
   
    surface_set_target(surface_Enemy_Sprite);

    draw_clear_alpha(c_white, 0);
    draw_set_color(c_white);
   
    draw_set_blend_mode_ext(bm_inv_dest_color, bm_inv_src_color);
    draw_sprite(sprite_index, image_index, 0, 0);
    draw_set_blend_mode(bm_normal);

    surface_reset_target();
    draw_surface(surface_Enemy_Sprite, x, y);
   
    surface_free(surface_Enemy_Sprite);
}
else
{
    // draw sprite regularly
    draw_sprite(sprite_index, image_single, x, y);
};

The result is that (almost?) all the enemy sprites turn invisible as well as the character sprites (excl shadow) and the hud images. That makes absolutely no sense to me. Anybody see what's wrong in the code that might have caused this?
Title: Re: Negative sprites in Gamemaker (round 2)
Post by: Martijn dh on July 27, 2009, 08:07:50 pm
Never mind. The code is not the problem. Appearantly GM starts to experience errors when you try to switch targets within a draw event. So I'm now using the End Step event to set the surface and the draw event to use and destroy it.

Again. Thanks for the help.
Title: Re: Negative sprites in Gamemaker (round 2)
Post by: Xfixium on July 27, 2009, 10:58:02 pm
Ah yes, changing the target in the draw event is a no no. Forgot about that. Weirdly It worked for my little test, but I didn't draw anything else.
Title: Re: Negative sprites in Gamemaker (round 2)
Post by: Nambiyo on July 31, 2009, 07:55:12 am
Ah yes, changing the target in the draw event is a no no. Forgot about that. Weirdly It worked for my little test, but I didn't draw anything else.

why didn't u? u shud

Contact Us | Legal | Advertise Here
2013 © ZFGC, All Rights Reserved