mirror of
https://github.com/4ian/GDevelop.git
synced 2025-10-15 10:19:04 +00:00
Add an expression to get the number of frames in the current animation of a sprite object (#4722)
This commit is contained in:
@@ -583,7 +583,14 @@ void GD_CORE_API BuiltinExtensionsImplementer::ImplementsSpriteExtension(
|
||||
|
||||
obj.AddExpression("Sprite",
|
||||
_("Image"),
|
||||
_("Animation frame of the object"),
|
||||
_("Current frame of the animation of the object"),
|
||||
_("Animations and images"),
|
||||
"res/actions/sprite.png")
|
||||
.AddParameter("object", _("Object"), "Sprite");
|
||||
|
||||
obj.AddExpression("AnimationFrameCount",
|
||||
_("Number of frames"),
|
||||
_("Number of frames in the current animation of the object"),
|
||||
_("Animations and images"),
|
||||
"res/actions/sprite.png")
|
||||
.AddParameter("object", _("Object"), "Sprite");
|
||||
|
@@ -108,6 +108,7 @@ SpriteExtension::SpriteExtension() {
|
||||
spriteExpressions["Animation"].SetFunctionName("getAnimation");
|
||||
spriteStrExpressions["AnimationName"].SetFunctionName("getAnimationName");
|
||||
spriteExpressions["Sprite"].SetFunctionName("getAnimationFrame");
|
||||
spriteExpressions["AnimationFrameCount"].SetFunctionName("getAnimationFrameCount");
|
||||
spriteExpressions["AnimationSpeedScale"].SetFunctionName(
|
||||
"getAnimationSpeedScale");
|
||||
spriteExpressions["ScaleX"].SetFunctionName("getScaleX");
|
||||
|
@@ -754,6 +754,17 @@ namespace gdjs {
|
||||
return this._currentFrame;
|
||||
}
|
||||
|
||||
getAnimationFrameCount(): number {
|
||||
if (this._currentAnimation >= this._animations.length) {
|
||||
return 0;
|
||||
}
|
||||
const currentAnimation = this._animations[this._currentAnimation];
|
||||
if (this._currentDirection >= currentAnimation.directions.length) {
|
||||
return 0;
|
||||
}
|
||||
return currentAnimation.directions[this._currentDirection].frames.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* Return true if animation has ended.
|
||||
|
Reference in New Issue
Block a user