Материал из Поле цифровой дидактики

Шаблон:Stub A hitbox is a shape that detects collision with other objects. The purpose of a hitbox is to detect collision with a simpler shape such as a circle or a rectangle, as more detailed images can affect how smoothly the game runs. Like the name suggests, hitboxes are often simple shapes, being the same general size as the sprite it is sensing collisions for.

Scratch Cat with a suitable hitbox.

Uses of a Hitbox

Hitboxes are great ways of avoiding unnecessary lag in platformers and other similar games, and are also used for more detailed characters/player avatars. They generally make projects run smoother. When making a hitbox, it is essential that it is roughly the same size as the player; otherwise the hitbox can make games very inaccurate.Шаблон:Citation needed Here are some methods in which you can program your own hitbox:

Different Sprite Method

This method uses two sprites.

Drawing a Hitbox

To start, create a new sprite for the hitbox and open the "Costumes" tab. If you haven't already, backpack (or download onto your computer if you are using the offline editor) the first costume for your character, then upload it into a blank vector costume in your hitbox sprite. Using the rectangle tool, draw a rectangle over your character and make it as small possible without any part of the character showing. When you remove the character from behind, you will have your hitbox.

Programming the Hitbox

After you have made the sprite, you will need a platformer script inside the scripts area. If you don't know how to make one, a tutorial can be found here.

Linking the Two Sprites

Now that you have made the hitbox, you need to connect the character to it. Put this script in the character sprite:

when gf clicked
  go to [Hitbox v]

Different Costume Method

This method uses one sprite with two different costumes.

Drawing the Costume

Duplicate the original costume. Rename it to "Hitbox". Then, create a rectangle that is roughly the same size and dimensions as the character. You can now delete the original character in the "Hitbox".

Using the Costume

The sprite will need a platformer script. After it has those scripts, put these blocks inside the main loop:

when gf clicked
  switch costume to [Hitbox v]
  ... //main loop
  switch costume to [Original Costume v]

When you run your project, everything should be smoother.