Scratch for Java

Sprite::setHitbox()

Sets the hitbox of the sprite.

Examples

import org.openpatch.scratch.*;
 
public class SpriteSetHitbox {
  public SpriteSetHitbox() {
    Stage myStage = new Stage(600, 240);
    myStage.setDebug(true);
    Sprite mySprite = new Sprite("zeta", "assets/zeta_green_badge.png");
    myStage.add(mySprite);
    myStage.wait(2000);
    int x[] = {0, 10, 10, 0};
    int y[] = {0, 0, 10, 10};
    mySprite.setHitbox(x, y);
    myStage.wait(2000);
    myStage.exit();
  }
 
  public static void main(String[] args) {
    new SpriteSetHitbox();
  }
}
 

View on GitHub

Syntax

Java

.setHitbox(xcoordinates, ycoordinates)
.setHitbox(hitbox)
.setHitbox(...coordinates)

Scratch

set hitbox (hitbox)

Parameters

Name Data Type Description
xcoordinates int[] An array of xcoordinates
ycoordinates int[] An array of ycoordinates
hitbox Hitbox A hitbox
...coordinates int A variable argument list, which has the following structure: x1, y1, x2, y2, x3, y3 ...

Return

boolean

setHitbox()