Document stub.png This article is a stub. It may be incomplete, unfinished, or have missing parts/sections. If the article can be expanded, please do so! There may be suggestions on its talk page. (May 2018)

Hitboxes are common methods used for overworlds, platformers, etc. They are used as the shape that collide with other objects, as more detailed images can affect how smoothly the game runs. Like the name suggests, it's usually just a black rectangle, being the same general size.

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
forever
  go to [Hitbox v]
end

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
forever
  switch costume to [Hitbox v]
  ... //main loop
  switch costume to [Original Costume v]

When you run your project, everything should be smoother.

Cookies help us deliver our services. By using our services, you agree to our use of cookies.