Class AnimatedSprite
java.lang.Object
org.openpatch.scratch.Sprite
org.openpatch.scratch.extensions.animation.AnimatedSprite
The AnimatedSprite class represents a sprite that can play animations. It extends the Sprite
class and provides methods to add animations, play animations, set the interval between animation
frames, and reset the animation.
Example usage:
AnimatedSprite sprite = new AnimatedSprite();
sprite.addCostume("idle", "assets/idle.png");
sprite.addAnimation("walk", "assets/walk_%d.png", 4);
sprite.playAnimation("walk");
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addAnimation
(String name, String pattern, int frames) Adds an animation to the sprite.void
addAnimation
(String name, String path, int frames, int width, int height) Adds an animation to the sprite.void
addAnimation
(String name, String path, int frames, int width, int height, int row) Adds an animation to the sprite.void
addAnimation
(String name, String path, int frames, int width, int height, int column, boolean useColumns) Adds an animation to the sprite.int
Gets the current animation frame.int
Gets the interval between animation frames.boolean
Checks if the animation is played.void
playAnimation
(String name) Plays the animation with the specified name.void
playAnimation
(String name, boolean once) Plays the animation with the specified name.void
Resets the animation.void
setAnimationFrame
(int frame) Sets the current animation frame.void
setAnimationInterval
(int interval) Sets the interval between animation frames.Methods inherited from class org.openpatch.scratch.Sprite
addCostume, addCostume, addCostumes, addShader, addSound, addTimer, broadcast, broadcast, changeSize, changeTint, changeTransparency, changeX, changeY, disableHitbox, distanceToMousePointer, distanceToSprite, enableHitbox, getCurrentCostumeIndex, getCurrentCostumeName, getCurrentDay, getCurrentDayOfWeek, getCurrentHour, getCurrentMillisecond, getCurrentMinute, getCurrentMonth, getCurrentSecond, getCurrentShader, getCurrentShaderIndex, getCurrentShaderName, getCurrentYear, getDaysSince2000, getDeltaTime, getDirection, getHeight, getHitbox, getMouse, getMouseX, getMouseY, getPen, getPosition, getShader, getSize, getStage, getText, getTimer, getTimer, getTint, getTouchingSprite, getTouchingSprites, getWidth, getX, getY, goLayersBackwards, goLayersForwards, goToBackLayer, goToFrontLayer, goToMousePointer, goToRandomPosition, goToSprite, hide, ifOnEdgeBounce, isKeyPressed, isMouseDown, isSoundPlaying, isTouchingEdge, isTouchingMousePointer, isTouchingSprite, isTouchingSprite, isUI, isUI, isVisible, keyEvent, mouseEvent, move, move, nextCostume, nextShader, pickRandom, playSound, pointInDirection, pointInDirection, pointTowardsMousePointer, pointTowardsSprite, remove, removeSound, removeTimer, resetShader, run, say, say, setDirection, setDirection, setHitbox, setHitbox, setHitbox, setHitbox, setOnEdgeBounce, setPosition, setPosition, setRotationStyle, setSize, setTint, setTint, setTint, setTransparency, setX, setY, show, stamp, stampToBackground, stampToForeground, stampToUI, stopAllSounds, stopSound, switchCostume, switchCostume, switchShader, switchShader, think, think, turnLeft, turnRight, whenAddedToStage, whenAddedToStage, whenBackdropSwitches, whenClicked, whenIReceive, whenIReceive, whenKeyPressed, whenKeyReleased, whenMouseClicked, whenMouseMoved, whenRemovedFromStage, whenRemovedFromStage
-
Constructor Details
-
AnimatedSprite
public AnimatedSprite()
-
-
Method Details
-
addAnimation
Adds an animation to the sprite.- Parameters:
name
- the name of the animationpattern
- the pattern (@see String#format) of the file namesframes
- the number of frames in the animation
-
addAnimation
Adds an animation to the sprite.- Parameters:
name
- the name of the animationpath
- the path to the animation framesframes
- the number of frames in the animationwidth
- the width of each frameheight
- the height of each frame
-
addAnimation
Adds an animation to the sprite.- Parameters:
name
- the name of the animationpath
- the path to the animation framesframes
- the number of frames in the animationwidth
- the width of each frameheight
- the height of each framerow
- the row of the animation frames
-
addAnimation
public void addAnimation(String name, String path, int frames, int width, int height, int column, boolean useColumns) Adds an animation to the sprite.- Parameters:
name
- the name of the animationpath
- the path to the animation framesframes
- the number of frames in the animationwidth
- the width of each frameheight
- the height of each framecolumn
- the column of the animation framesuseColumns
- whether to use columns or rows
-
playAnimation
Plays the animation with the specified name.- Parameters:
name
- the name of the animation to play
-
playAnimation
Plays the animation with the specified name.- Parameters:
name
- the name of the animation to playonce
- whether to play the animation once
-
resetAnimation
public void resetAnimation()Resets the animation. The animation will start from the first frame. -
setAnimationInterval
public void setAnimationInterval(int interval) Sets the interval between animation frames.- Parameters:
interval
- the interval between animation frames
-
getAnimationInterval
public int getAnimationInterval()Gets the interval between animation frames.- Returns:
- the interval between animation frames
-
getAnimationFrame
public int getAnimationFrame()Gets the current animation frame.- Returns:
- the current animation frame
-
setAnimationFrame
public void setAnimationFrame(int frame) Sets the current animation frame.- Parameters:
frame
- the current animation frame
-
isAnimationPlayed
public boolean isAnimationPlayed()Checks if the animation is played.- Returns:
- true if the animation is played, false otherwise
-