Jump to content


Mnementh

Member Since 28 Jun 2007
Offline Last Active Jun 17 2013 05:59 AM

Topics I've Started

Composite Datatypes

31 December 2008 - 03:47 AM

Composite Datatypes

This extension allows the user to easily create and use composite datatypes. It is available as an extension or a GML file.

Extension
GML File

Functions
  • cdt_init  --  Initilize the system. It must be called before any other use (done automatically in the extension).
  • cdt_free  --  Free the memory used by the system (called automatically in the extension).
  • cdt_create(fields) --  Create an instance of a composite datatype with a number of data fields. Returns the id.
  • cdt_destroy(cdt) --  Destroy an instance of a cdt.
  • cdt_set_field(cdt, field, value) --  Set one of the fields in an instance of a cdt to a value.
  • cdt_get_field(cdt, field)  --  Returns the value of one of the fields in an instance of a cdt.

----------

I made this simply because I got tired of reproducing the same functionality every time that I made an extension. I hope that people find it useful, for making both their own extensions, and their own games.


Drawing Text On Surfaces

20 August 2008 - 01:44 AM

Hey Guys. I'm having a strange issue here, and I don't know whether it's GM, or my computer, so I decided to ask.

Basically, I'm working on an extension that's going to be drawing text. So, in order to accelerate that, I'm drawing it to a surface only when it needs updating, and drawing the surface every step. Simple enough.

Now, what's weird, is that the text looks different when it's drawn to the surface. It's much less substantial, as if the text that was drawn normally was bold, and the text drawn on the surface was not. This happens almost every font, however several seem not to be effected (the only one I can think of now is Gungsuh).

Do you think this is a issue with my computer, or GM? Either way, it's not that important, but if there is something that I can do to fix this, I would like to know about it.

Thanks.

Create
{
	draw_set_font(font0);

	width = string_width("Hello World!");
	height = string_height("Hello World!");
	
	surface = surface_create(width,height);
	
	surface_set_target(surface);
	
		draw_clear_alpha(c_black,0);
		
		draw_text(0,0,"Hello World!");
		
	surface_reset_target();
}

Draw
{
	draw_surface(surface,10,10);
	
	draw_text(10,30,"Hello World!");
}

Emulating Keyboard_string

12 August 2008 - 05:02 PM

Hey guys. I was wondering if anyone knew of an easy way of emulating the functionality provided by keyboard_string. Basically, I'm creating an extension, and I want the user to be able to add it to their game with minimal difficulty. However, the extension includes an object that watches the value of keyboard_string, and when It sees new characters, it removes them. I want this same functionality, without changing the value of keyboard_string.

Thanks.

Problem Using Textured Primitives

27 July 2008 - 03:58 AM

So, I've been trying to make a sprite look like it was 'crumpled', and I'm using textured primitives to do it. I got my code to work with one sprite. However, I'm having trouble using other sprites, and I was wondering if anyone knew why. Basically, I only see part of the sprite, instead of the whole image.

Create
{
	// Get the texture of the sprite we want to crumple.
	texTexture = sprite_get_texture(sprStars,0);
	
	// Set up a few predefined values. This is mainly for ease-of-use.
	SPRITE_WIDTH = sprite_get_width(sprStars);
	SPRITE_HEIGHT = sprite_get_height(sprStars);
	TEXTURE_WIDTH = texture_get_width(texTexture);
	TEXTURE_HEIGHT = texture_get_height(texTexture);
	
	
	// These values will control the size of the individual triangles 
	// that will create the 'crumpled' effect. Larger triangles will 
	// create a coarser effect, and increase speed, while smaller 
	// triangles will give a finer, but slower effect. The width of 
	// the sprite should be evenly divisible by the width of the 
	// triangle, and the height of the sprite should be evenly 
	// divisible by the height of the triangles 
	TRIANGLE_WIDTH = 8;
	TRIANGLE_HEIGHT = 8;
	
	
	// This value controls the range of values in which a texture 
	// vertex may be created. The higher the value, the more 'crumpled'
	// the image will appear
	RANDOM_FACTOR = 10;
	
	
	// Normally, when looping through a set of values, we start at the 
	// left bound, and stop directly before the right boundary. However, 
	// in these next two loops, we will include the right bound.
	
	// Set up the texture vertices. These vertices will define the points 
	// on the texture to use for the primitive.
	var _x, _y;
	for (_x = 0; _x <= SPRITE_WIDTH / TRIANGLE_WIDTH; _x += 1)
	{
		for (_y = 0; _y <= SPRITE_HEIGHT / TRIANGLE_HEIGHT; _y += 1)
		{
			TextureX[_x,_y] = _x / (SPRITE_WIDTH / TRIANGLE_WIDTH) * TEXTURE_WIDTH;
			TextureY[_x,_y] = _y / (SPRITE_HEIGHT / TRIANGLE_HEIGHT) * TEXTURE_HEIGHT;
		}
	}
	
	
	// Set up the triangle vertices. These vertices will define the points 
	// at which the triangles that will define the primitive are created. 
	// These values will be randomized, which will give create the effect. 
	var _x, _y;
	for (_x = 0; _x <= SPRITE_WIDTH / TRIANGLE_WIDTH; _x += 1)
	{
		for (_y = 0; _y <= SPRITE_HEIGHT / TRIANGLE_HEIGHT; _y += 1)
		{
			TriangleX[_x,_y] = _x * TRIANGLE_WIDTH - RANDOM_FACTOR + random(RANDOM_FACTOR * 2);
			TriangleY[_x,_y] = _y * TRIANGLE_HEIGHT - RANDOM_FACTOR + random(RANDOM_FACTOR * 2);
		}
	}
}

Draw
{
	draw_set_color(c_white);

	draw_primitive_begin_texture(pr_trianglelist,texTexture);

	var _x, _y;
	for (_x = 0; _x < SPRITE_WIDTH / TRIANGLE_WIDTH; _x += 1)
	{
		for (_y = 0; _y < SPRITE_HEIGHT / TRIANGLE_HEIGHT; _y += 1)
		{
			// define first triangle
			draw_vertex_texture(x + TriangleX[_x,_y],y + TriangleY[_x,_y],TextureX[_x,_y],TextureY[_x,_y]);
			draw_vertex_texture(x + TriangleX[_x+1,_y],y + TriangleY[_x+1,_y],TextureX[_x+1,_y],TextureY[_x+1,_y]);
			draw_vertex_texture(x + TriangleX[_x,_y+1],y + TriangleY[_x,_y+1],TextureX[_x,_y+1],TextureY[_x,_y+1]);
			draw_vertex_texture(x + TriangleX[_x+1,_y],y + TriangleY[_x+1,_y],TextureX[_x+1,_y],TextureY[_x+1,_y]);
			draw_vertex_texture(x + TriangleX[_x,_y+1],y + TriangleY[_x,_y+1],TextureX[_x,_y+1],TextureY[_x,_y+1]);
			draw_vertex_texture(x + TriangleX[_x+1,_y+1],y + TriangleY[_x+1,_y+1],TextureX[_x+1,_y+1],TextureY[_x+1,_y+1]);
		}
	}
	
	draw_primitive_end();
}

Thanks.

Instance Deactivation In View

25 July 2008 - 02:43 AM

Quick question, for those that have experience with this. Is it better to activate all instances of a particular object, and then deactivate those outside the view, or deactivate them all, and then activate those inside the view. I'd guess the second, but the help file provides the first as an example, so...

Thanks.