Install Steam
login
|
language
简体中文 (Simplified Chinese)
繁體中文 (Traditional Chinese)
日本語 (Japanese)
한국어 (Korean)
ไทย (Thai)
Български (Bulgarian)
Čeština (Czech)
Dansk (Danish)
Deutsch (German)
Español - España (Spanish - Spain)
Español - Latinoamérica (Spanish - Latin America)
Ελληνικά (Greek)
Français (French)
Italiano (Italian)
Bahasa Indonesia (Indonesian)
Magyar (Hungarian)
Nederlands (Dutch)
Norsk (Norwegian)
Polski (Polish)
Português (Portuguese - Portugal)
Português - Brasil (Portuguese - Brazil)
Română (Romanian)
Русский (Russian)
Suomi (Finnish)
Svenska (Swedish)
Türkçe (Turkish)
Tiếng Việt (Vietnamese)
Українська (Ukrainian)
Report a translation problem
For example, if I made an army tank and wanted to add a gun turret to it. I could just do this in the draw event...
Things are drawn in the order (layered) based on what comes first.
'draw_self();' tells the object to draw the sprite it was originally assigned. Anytime you make your own draw event for an object it overrides it drawing itself by default so you have to tell it to draw when you want it to.
'draw_sprite(spr_turret, 0, x, y);' will tell it to draw the sprite of my turret. The 0 is what frame you want the sprite you're drawing to show. In this code snippet I'm assuming there is only a single frame so I draw it at 0. The x / y is the location on the screen to draw it at. Since I just put 'x' and 'y' its using the objects x / y origin point so in this case I'm assuming the origin of the tank player object is where the turret would attach. By using 'draw_sprite' I'm also assuming the rotation of the object won't ever change.
If I wanted the turret to rotate I'd use 'draw_sprite_ext' since that allows you to specify an angle to have the sprite facing. If my tank objects origin point isn't where I want the turret to attach then I'd have to use the 'lengthdir_x' and 'lengthdir_y' functions to calculate the position to place the turret.
Alternatively, there isn't much stopping you from just making another object to be the attached piece and then in its step event assigning its x / y position to the location where you want it to be attached to. Unless your game is super demanding on performance, such as having hundreds of objects on screen each with other objects "attached" to them and some really crazy collision code, it really shouldn't noticeably affect your game.