mirror of
https://github.com/Heretek-AI/GDevelop.git
synced 2026-07-22 01:55:25 -04:00
deb802cfec
* For now, this is limited to instances inside custom objects. This will be made available in the future for all instances in scenes if this works well.
120 lines
2.8 KiB
TypeScript
120 lines
2.8 KiB
TypeScript
/*
|
|
* GDevelop JS Platform
|
|
* Copyright 2013-2023 Florian Rival (Florian.Rival@gmail.com). All rights reserved.
|
|
* This project is released under the MIT License.
|
|
*/
|
|
namespace gdjs {
|
|
/** @category Behaviors > Default behaviors */
|
|
export interface Scalable {
|
|
/**
|
|
* Change the scale on X and Y axis of the object.
|
|
*
|
|
* @param newScale The new scale (must be greater than 0).
|
|
*/
|
|
setScale(newScale: float): void;
|
|
|
|
/**
|
|
* Change the scale on X axis of the object (changing its width).
|
|
*
|
|
* @param newScale The new scale (must be greater than 0).
|
|
*/
|
|
setScaleX(newScale: float): void;
|
|
|
|
/**
|
|
* Change the scale on Y axis of the object (changing its height).
|
|
*
|
|
* @param newScale The new scale (must be greater than 0).
|
|
*/
|
|
setScaleY(newScale: float): void;
|
|
|
|
/**
|
|
* Get the scale of the object (or the geometric mean of the X and Y scale
|
|
* in case they are different).
|
|
*
|
|
* @return the scale of the object (or the geometric mean of the X and
|
|
* Y scale in case they are different).
|
|
*/
|
|
getScale(): float;
|
|
|
|
/**
|
|
* Get the scale of the object on Y axis.
|
|
*
|
|
* @return the scale of the object on Y axis
|
|
*/
|
|
getScaleY(): float;
|
|
|
|
/**
|
|
* Get the scale of the object on X axis.
|
|
*
|
|
* @return the scale of the object on X axis
|
|
*/
|
|
getScaleX(): float;
|
|
}
|
|
|
|
/**
|
|
* A behavior that forwards the Scalable interface to its object.
|
|
* @category Behaviors > Default behaviors
|
|
*/
|
|
export class ScalableBehavior
|
|
extends gdjs.RuntimeBehavior
|
|
implements Scalable
|
|
{
|
|
private object: gdjs.RuntimeObject & Scalable;
|
|
|
|
constructor(
|
|
instanceContainer: gdjs.RuntimeInstanceContainer,
|
|
behaviorData,
|
|
owner: gdjs.RuntimeObject & Scalable
|
|
) {
|
|
super(instanceContainer, behaviorData, owner);
|
|
this.object = owner;
|
|
}
|
|
|
|
usesLifecycleFunction(): boolean {
|
|
return false;
|
|
}
|
|
|
|
override applyBehaviorOverriding(behaviorData): boolean {
|
|
// Nothing to update.
|
|
return true;
|
|
}
|
|
|
|
onDeActivate() {}
|
|
|
|
onDestroy() {}
|
|
|
|
doStepPreEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}
|
|
|
|
doStepPostEvents(instanceContainer: gdjs.RuntimeInstanceContainer) {}
|
|
|
|
setScale(newScale: float): void {
|
|
this.object.setScale(newScale);
|
|
}
|
|
|
|
setScaleX(newScale: float): void {
|
|
this.object.setScaleX(newScale);
|
|
}
|
|
|
|
setScaleY(newScale: float): void {
|
|
this.object.setScaleY(newScale);
|
|
}
|
|
|
|
getScale(): float {
|
|
return this.object.getScale();
|
|
}
|
|
|
|
getScaleY(): float {
|
|
return this.object.getScaleY();
|
|
}
|
|
|
|
getScaleX(): float {
|
|
return this.object.getScaleX();
|
|
}
|
|
}
|
|
|
|
gdjs.registerBehavior(
|
|
'ScalableCapability::ScalableBehavior',
|
|
gdjs.ScalableBehavior
|
|
);
|
|
}
|