gamemaker 3d drawing all sprites

eleven.ane Using sprites to create models

Every bit you probably know Game Maker is not considered a programme for creation of 3D games. Basically, what GM does is create two-dimensional games using three- dimensional graphics. Merely you can also still use two-dimensional graphics (sprites) in 3-dimensional space. You can employ 3D models but you tin can also use second models. Y'all can utilize them in such a way that they e'er face the camera, you can use them to create virtual rotation or even apply blitheness. There are many reasons why y'all would utilize 2D models (Flat Sprite Models) even when you could use 3D ones. This tutorial consists of four parts (A to D), each with its own gm6 file. Allow'southward take a await at the the start part in which we will meet how to draw a sprite on the floor.

xi.ii drawing a sprite on the floor

In the gm6 file (part A) we have a pretty straightforward Commencement Person Shooter with a mouselook script scr_mouselook:

//MOUSELOOK //get display dimensions display_w=display_get_width(); display_h=display_get_height(); //summate movement change_x=(display_mouse_get_x()-display_w/two)/sixteen; change_y=(display_mouse_get_y()-display_h/2)/12; //motion cam direction-=change_x zdirection+= change_y //set mouse dorsum display_mouse_set(display_w/two,display_h/2);

This ways we will exist able to look around in the virtual 3D space. And we will draw a ground in the script scr_draw_ground:

//draw footing d3d_draw_floor(-8192, -8192, 0, 8192, 8192, 0, background_get_texture(bk_ground),1024/eight,1024/six);

That code will probably non raise many eyebrows. So, at present that we have a basis, let's draw a sprite on information technology, in the script scr_draw_arrow:

//draw arrow d3d_set_depth(ane); draw_sprite_ext(spr_arrow, one, x, y, i, 1, point_direction(x,y,obj_character.x,obj_character.y), c_white, i);

Commencement, we ready the depth to ane (which is simply to a higher place the ground which is at zero). Then we depict the sprite spr_arrow. The rotation value volition be set in such a way that it always points at the Graphic symbol. Of course, you can use any other value that y'all want. If you lot run the gm6 file (part A) and walk around in the virtual space, you volition see that there are arrows on the footing that go along pointing at you lot. Okay, prepare for the next step? Read on.

11.three Making a sprite face the role player

When all the enemies in your game are lying dead on the floor, the previous part (A) was useful. Only what if they are nevertheless standing? Then you would need to drawsprite that is upright, facing the player. Nosotros volition apply an image of a ball and draw using the script draw_ball:

//draw ball d3d_transform_set_identity(); d3d_transform_add_rotation_x(9 0); d3d_transform_add_rotation_z(point_direction(10, y, obj_character.x, obj _Character.y)+90); d3d_transform_add_translation(x, y, z+32) draw_sprite_ext(spr_ball, 1, 0, 0, ane, i, 0, c_white, 1); d3d_transform_set_identity();

We will accept to apply transformation to get the epitome to stay upright. This is done in the line:

d3d_transform_add_rotation_x(90);

Rotating it in this way (10 axis, 90 degrees) volition make it look similar a traffic sign that hasn't been knocked over however. Next, we volition take to make the traffic sign face the player at all times. Once again, this is done using transformation in the line:

d3d_transform_add_rotation_z(point_direction(ten, y, obj_character.x, obj_character.y)+90);

Now the traffic sign will face the player at all times (using rotation around the z axis). That's it? Yep. If you run the gm6 (office B), you volition see a brawl that will always face the player. Just, you lot might ask, what if I would want to use an animated sprite? No trouble. Read on.

11.iv An animation that faces the player

Y'all can use the verbal same principle of transformation if you're using an animated sprite as y'all tin see if you run the gm6 file (part C). We will be using a flame sprite animation that consists of 10 subimages.

//draw flame d3d_transform_set_identity(); d3d_transform_add_rotation_x(90); d3d_transform_add_rotation_z(point_direction(x, y, obj_character.x, obj_character.y)+ninety); d3d_transform_add_translation(x, y, z) draw_sprite_ext(spr_flame,image_index,0,0,ane,1,0,c_white,1); d3d_transform_set_identity();

Information technology's the same thing (as in part B) except for the line:

draw_sprite_ext(spr_flame, image_index, 0, 0, 1, ane, 0, c_white, i);

This time we volition utilize 'image_index' and then that the sprite is animated. That's it. But what if you would want to walk around an object? Well, read on.

11.5 Using virtual rotation

Virtual rotated Flat Sprite Models are not really 3D models. They are Flat Sprite Models, so they're 2d. The trick is to set an epitome for each angle. Have a look at the gm6 file (role D) and the script draw_virtual and y'all will encounter it's basically the same code (as role C):

//don't describe if too far from camera if distance_to_object (obj_camera)>2048 then exit;

The first part (above) is used to avoid having to draw objects that are too far to see anyway. This has cypher to do with transformation. The next part (beneath) of the aforementioned script has and looks similar this:

//draw virtual rotating ball d3d_transform_set_identity(); d3d_transform_add_rotation_x(90); d3d_transform_add_rotation_z(point_direction(x, y, obj_character.x, obj_character.y)+ninety); d3d_transform_add_translation(x, y, z+64) draw_sprite_ext(spr_virtual, image_index, 0, 0, 1, 1, 0, c_white, 1); d3d_transform_set_identity();

This fourth dimension we volition use almost the same lawmaking, using the image_index value but in the Stride event we volition run the script scr_virtual that looks like this:

//set angle and paradigm angle=point_direction(10, y, obj_character.x, obj_character.y) image_index=bending*8/360;

Using the angle of the thespian in relation to the object, we volition set the value of the image_index. Because we're using 8 sub-images, nosotros volition use the number viii (last line, higher up). If yous run the gm6 (part D), you will see that the object rotates so that the histrion can view it from all sides. The more images you use, the more realistic the effect volition be. Just using more than subimages will result in a larger overall file size because images take upwards memory.


All rights reserved. Copyright © 2004 past John J.A.H. Weeren. Unauthorized use or reproduction, whole or in part, without written permission from the author is strictly prohibited. This page is part of the tutorial 3D For GML. Reproduced with permission. For more information, please run into the talk page.

trautmanhalown.blogspot.com

Source: https://enigma-dev.org/docs/Wiki/3D_for_GML:_Flat_sprite_models

0 Response to "gamemaker 3d drawing all sprites"

Yorum Gönder

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel