Jump to content


DarkSentinel

Member Since 26 Sep 2008
Offline Last Active Private

Topics I've Started

*_get_texture

18 May 2009 - 06:00 PM

I'm wondering how exactly the GM resources relate to textures. From my understanding, the internal resources are custom objects, and one of their private variables is a texture, and using *_get_texture() just returns the index to the texture. Is this correct or does the function do something else as well?

Stretch Part Of A Sprite

23 March 2009 - 01:22 PM

This is a code that is not very hard to make, but is really annoying to remember (for me at least). This draws a sprite, with the specified part stretched. It can be used to stretch sprites, while keeping the detail of the outer edges, like you would need for a button or message box that has shading. I couldn't think of a good name for the script, so suggestions are welcome.
[codebox]var sprite,subimg,xx,yy,xl,xr,yu,yd,hstretch,vstretch,
sprw,sprh,wi,hi;

sprite = argument0;
subimg = argument1;
xx = argument2;
yy = argument3; //position to draw the sprite
xl = argument4; //left boundary, anything to the left of this is not stretched horizontally
xr = argument5; //right boundary, anything to the right of this is not stretched horizontally
yu = argument6; //upper boundary, anything above this is not stretched vertically
yd = argument7; //lower boundary, anything below this is not stretched vertically
hstretch = max(argument8,0); //how much the sprite is stretched horizontally
vstretch = max(argument9,0); //how much the sprite isstretched vertically

sprw = sprite_get_width(sprite);
sprh = sprite_get_height(sprite);
wi = xr-xl;
hi = yd-yu

//top parts
draw_sprite_part (sprite,subimg, 0, 0, xl, yu, xx, yy);
draw_sprite_part_ext(sprite,subimg, xl, 0, wi, yu, xx+xl, yy, hstretch,1, c_white,1);
draw_sprite_part (sprite,subimg, xr, 0, sprw-xr, yu, xx+xl+wi*hstretch, yy);


//midddle parts
draw_sprite_part_ext(sprite,subimg, 0, yu, xl, hi, xx, yy+yu, 1, vstretch, c_white,1);
draw_sprite_part_ext(sprite,subimg, xl, yu, wi, hi, xx+xl, yy+yu, hstretch,vstretch, c_white,1);
draw_sprite_part_ext(sprite,subimg, xr, yu, sprw-xr, hi, xx+xl+wi*hstretch, yy+yu, 1, vstretch, c_white,1);

//bottom parts
draw_sprite_part (sprite,subimg, 0, yd, xl, sprh-yd, xx, yy+yu+hi*vstretch);
draw_sprite_part_ext(sprite,subimg, xl, yd, wi, sprh-yd, xx+xl, yy+yu+hi*vstretch, hstretch,1, c_white,1);
draw_sprite_part (sprite,subimg, xr, yd, sprw-xr, sprh-yd, xx+xl+wi*hstretch, yy+yu+hi*vstretch);[/codebox]

Sprite Create From Screen

08 January 2009 - 08:42 PM

I'm making a stickman animator program. You place nodes down, connect them how you want then move them around to animate it. I'm using gm6 so I don't have sprite_save, so instead I draw everything to a surface and save that (if there is another way please tell me).
My room size is currently 200*200 but I plan on making it smaller (because it represents the actual sprite size). I moved the view0 slightly left and up so that the room is centered in a 640*480 window. I use a second view (view1) that is an enlargement of the room only so that it is easier to work with.

I'm having some trouble using sprite_create_from_screen in my program. Here is the code I am currently using:
PRE
var l,i,spr,vx,vy;
vx = view_xview[0];
vy = view_yview[0];
view_xview[0] = 0;
view_yview[0] = 0;

view_visible[1] = false;
with(joint)
{
    visible = false;
}
l = control.keyframe;
jump_to_frame(0);
screen_redraw();
spr = sprite_create_from_screen(0,0,room_width,room_height,0,0,0,0,0,0);
for(i=1; i<=ds_list_find_value(l,ds_list_size(l)-1); i+=1)
{
    jump_to_frame(i);
    screen_redraw();
    sleep(1000);
    sprite_add_from_screen(spr,0,0,room_width,room_height);
}

var sur;
sur = surface_create(room_width*sprite_get_number(spr),room_height);
surface_set_target(sur);
i = 0;
repeat(sprite_get_number(spr))
{
    draw_sprite(spr,i,i*room_width,0);
    i += 1;
}
surface_reset_target();
surface_save(sur,'d:\anim'+string(current_time)+'.bmp');

sprite_delete(spr);
surface_free(sur);
with(joint)
{
    visible = true;
}
view_visible[1] = true;
view_xview[0] = vx;
view_yview[0] = vy;


I added the sleep function to see if the program was repositioning the nodes but it doesn't do anything. view1 doesn't go away, view0 doesn't reposition, the nodes don't move. However the surface is created and the file is created. However it has only a quarter of the room in the bottom right corner.

I can't seem to find the problem. jump_to_frame is a script I made. I know thats not the problem because I use it outside of this script and it works fine. However if you need I will post it as well, just ask.

If you can tell me how to have images from mediafire show in my post I can show you a screenshot of what happens, and the output file.

Sorry if I seem incoherent, it's getting late.

EDIT: Never mind, I've fixed it. I was stupid and used screen_refresh instead redraw.

Transperancy Problem With Surfaces

31 October 2008 - 07:49 AM

I'm creating a script to create an animated sprite out of an old one. The problem is that i use surfaces to do this. Each time i draw the next frame i clear the surface in black. This means that the new sprite's black parts are transparent. Anyone know how to fix this? I tried clearing it with an alpha of 0 and setting it to non-transparent but it din't work

BTW i'm not just duplicating the sprite, i'm actually doing something to it first.

Drawing Wavy Sprites

29 October 2008 - 04:36 PM

Here's a script i made to draw a wavy sprite (sine wave).
var sprite, w, h, hor, xOff, yOff, ampl, wvln, shade, wvOff, xx, yy, col;
sprite = argument0;
ampl = argument1; //amplitude of the wave (maximum distance it should move)
wvln = argument2; //wavelength of the wave
xx = argument3;
yy = argument4;
hor = argument5; //true makes the wave go horizontal, false vertical
wvOff = argument6; //offset of the sine wave, incase you don't want it starting at 0 always, or you want it animated
shade = argument7; //true/false, whether you want shading or not
shdint = argument8; //shading intensity, keep below 127

w = sprite_get_width(sprite);
h = sprite_get_height(sprite);
xOff = sprite_get_xoffset(sprite);
yOff = sprite_get_yoffset(sprite);

if hor == true
{
	for(i=0; i<w; i+=1)
	{
		r = sin( degtorad( i/w*wvln-wvOff ) );
		if shade == true { col = make_color_hsv(0, 0, 255-(r+1)*shdint)}
		else { col = c_white};
		draw_sprite_part_ext(sprite, 0, 
							i, 0,					   //left top
							10, h,					  //width, height
							xx+i-xOff, yy-yOff+r*ampl,  //x y
							1, 1,					   //xscale, yscale
							col, 1);					//color, alpha
	}
}
else
{
	for(i=0; i<w; i+=1)
	{
		r = sin( degtorad( i/h*wvln-wvOff ) );
		if shade == true { col = make_color_hsv(0, 0, 255-(r+1)*shdint)}
		else { col = c_white};
		draw_sprite_part_ext(sprite, 0, 
							0, i,					   //left top
							h, 10,					  //width, height
							xx-xOff+r*ampl, yy-yOff+i,  //x y
							1, 1,					   //xscale, yscale
							col, 1);					//color, alpha
	}
}

To make the sprite wave continuously do this:

Create event
k = 0;

Step event
k+=1//replace 1 with how fast you want the wave to go
k = k mod 360//replace 360 with the wavelength you use in the draw function (argument2)

Draw event
draw_sprite_wave(sprite_index, 10, 360, x, y, true, k, true, 64);

I'm still busy creating the script to make a new sprite that will be created ingame because i don't think it's wise to use this too many times per step.

Any optimisations are welcome  :(
Also if you know any other methods for waves, i know photoshop has a few others...