08.11.2012 Views

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

Designing Games with Game Maker - YoYo Games

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

sprite_get_texture(spr,subimg) Returns the id of the texture<br />

corresponding to subimage subimg of the indicated sprite.<br />

background_get_texture(back) Returns the id of the texture<br />

corresponding to the indicated background.<br />

A selected texture might not yet be in video memory. The system will put it there once you<br />

need it but sometimes you want to decide this yourself. For this the following two functions<br />

exist:<br />

texture_preload(texid) Puts the texture immediately into video memory.<br />

texture_set_priority(texid,prio) When there is too little video<br />

memory some will be removed temporarily to make room for others that are<br />

needed. The ones <strong>with</strong> lowest priority are removed first. Default, all have<br />

priority 0 but you can change the priority here. (Use positive values!)<br />

To add textures to primitives you must specify which parts of the textures must be put where<br />

on the primitive. Positions in the texture are indicated <strong>with</strong> values between 0 and 1 but there<br />

is a problem here. Sizes of textures must be powers of 2 (so e.g. 32x32 or 64x64). If you<br />

want to use sprites or background as textures you better make sure they have such a size. If<br />

not, the test will be blank. To find out which part of the texture is actually used you can use<br />

the following two functions. They return a value between 0 and 1 that indicates the width or<br />

height of the actual part of the texture being used. Specifying this value as texture coordinate<br />

will indicate the right or bottom side of the texture.<br />

texture_get_width(texid) Returns the width of the texture <strong>with</strong> the<br />

given id. The width lies in the range 0-1.<br />

texture_get_height(texid) Returns the height of the texture <strong>with</strong> the<br />

given id. The height lies in the range 0-1.<br />

To draw textured primitives you use the following functions:<br />

draw_primitive_begin_texture(kind,texid) Start a primitive of the<br />

indicated kind <strong>with</strong> the given texture.<br />

draw_vertex_texture(x,y,xtex,ytex) Add vertex (x,y) to the primitive<br />

<strong>with</strong> position (xtex,ytex) in the texture, blending <strong>with</strong> the color and alpha<br />

value set before. xtex and ytex should normally lie between 0 and 1 but also<br />

larger values can be used, leading to a repetition of the texture (see below).

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!