Drawing Surface on Object?

C

Chatterb0x

Guest
Is it possible to set an object's sprite as a surface? I'm developing an orient themed game. The intent is to have sakura blossom object's act as a canvas catching enemy blood splatter. Each instance can wrap around the screen. Please advise which method is best.

Here is a screen from the game, Blind Samurai.

The tree and rock object cannot catch blood.
 
Last edited by a moderator:
K

Kreastricon62

Guest
I believe it is possible. I did the same thing, except that I was using a sprite as a mirror to reflect the player. The idea is the same, you are just drawing red stuff on a tree. It is also much easier because you are not consistently updating it like a mirror.

The first thing you have to do is create a COPY of your sprite and you want to set the negative space to the color BLACK and erase the actual sprite. You do know what I mean by negative space, right?

Now you can create a surface the exact same size as your sprite you want to catch the blood.

After you draw blood to the surface, you need to set the blend mode to bm_subtract, draw the negative sprite over it, set it to bm_normal, surface reset target, and bob's your uncle.

The code looks like this:

Code:
//Create Event
Surface=surface_create(sprite_width,sprite_height)


//Draw Event
draw_surface(Surface,x-sprite_xoffset,y-sprite_yoffset)

//Insert your code for drawing blood splatters on a sprite

//Draw the transparent part of the surface.
draw_set_blend_mode(bm_subtract)
draw_sprite(NEGATIVE_SPRITE,0,,x-sprite_xoffset,y-sprite_yoffset)
draw_set_blend_mode(bm_normal)

surface_set_target()
Let me know if this works.
 
C

Chatterb0x

Guest
I'll combine this with very similar code a contributor posted on the reddit. Thanks!
 
C

Chatterb0x

Guest
I bring glad tidings. Let me share with you knowledge hard won. Observe:
https://media.giphy.com/media/l2SpMABrxyxwqS13i/giphy.gif

It's just a matter of refining the splatter mechanic. Time to play Hotline Miami for inspiration!

obj_blossom
(sprite origin is 0,0)
Create Event
image_alpha = 0;
surface = surface_create(sprite_width, sprite_height)

Begin Step
hspeed = global_speed;
move_wrap(true, false, 0);

if(game_start){
surface_set_target(surface);
draw_clear_alpha(0,0);
draw_sprite(spr_blossom5,image_index,0,0);
surface_reset_target();
}

Game End
surface_free(surface);

Draw
if(game_start == 1){
image_alpha += .05; //Relic from previous code. Going to remove.
draw_surface(surface,x,y)
}

obj_blood
Create
image_xscale = random_range(0.33, 1);
image_yscale = image_xscale;
blood_direction = random(360);
blood_speed = random_range(3, 12);
blood_friction = random_range(blood_direction/8, blood_speed/2);
blood_size = random_range(image_xscale / 10, image_xscale / 5);

Step
//Setting speed and wrap arguments.
hspeed = global_speed;
move_wrap(true,false,0);

//Size changing
image_xscale -= blood_size;
image_yscale = image_xscale;

//Blood fades as it spreads. Friction slows blood.
if (blood_speed > 0){
image_alpha -= random_range(0.05, 0.1);
blood_speed = choose(blood_speed, 0, blood_friction);
}

End Step
//Actual splatter spread
x += lengthdir_x(blood_speed, blood_direction);
y += lengthdir_y(blood_speed, blood_direction);


Collision w/obj_blossom
with other{
draw_set_colour_write_enable(1,1,1,0);
surface_set_target(surface);
draw_sprite_ext(spr_blood, other.image_index, other.x-x, other.y-y, image_xscale, image_yscale, image_angle, c_white, image_alpha);
surface_reset_target();
draw_set_colour_write_enable(1,1,1,1);
}


Draw
///Don't draw.


Shout outs:
Zack Bell (INK) for blood tutorial
Vernurr (GameMaker Reddit) for .gml file
Thread contributors
 
Top