当前位置:网站首页>This of phaser3 add. sprite

This of phaser3 add. sprite

2022-06-13 01:25:00 Durian is not delicious

List of articles

sprite

var mysprite = this.add.sprite(...)

on(event, fn [, context]) Adds a listener for the given event .

animationrepeat Equate to Phaser.Animations.Events.ANIMATION_REPEAT
animationcomplete == Phaser.Animations.Events.ANIMATION_COMPLETE
animationcomplete-
animationrestart
animationstart == Phaser.Animations.Events.ANIMATION_START
animationstop == Phaser.Animations.Events.ANIMATION_STOP
animationupdate == Phaser.Animations.Events.ANIMATION_UPDATE

//animationrepeat  Animation repeat Events .  When the animation is repeated on it , This incident was caused by  Sprite  Dispatch .
mysprite.on('animationrepeat', listener)

setDepth(value) The depth of the game object in the scene .( Use setDepth: There will be no hard objects overlapping )

In some circumstances , Depth is also called “z-index”, It allows you to change the rendering order of game objects , Without actually moving them in the display list .
The default depth is zero . GameObjects with higher depth values will always appear before GameObjects with lower depth values .
Setting the depth will queue the depth sort events in the scene .

Parameters :
value Numbers The depth of this GameObject .


var troop1 = this.add.sprite(500, 340, 'soldier', 'Soldier_2_shot_up_1').play('shoot1');
var troop2 = this.add.sprite(500, 310, 'soldier', 'soldier_3_shoot_front_1').play('shoot2');
//  By default, the lower one will overwrite the upper one , namely troop2 covers troop1, At this point troop1 Cover troop2, You need color settings setDepth troop1 Greater than troop2

troop1.setDepth(2);
troop2.setDepth(1);

playAfterDelay(key, delay) Wait for the specified delay ( In Milliseconds ), Then start playing the given animation . When multiple objects have used an animation, the motion will stop at the same time , Use playAfterDelay You can set the delay

If the animation has a delay value set in its configuration , It will be added to the delay given here .
If an animation is already running and a new animation is given this method , It waits for a given delay before starting a new animation .
If no animation is currently running , The given animation starts after a delay .
stay Sprite When playing animation on , It first checks to see if it is possible to Sprite Matching key found locally . If possible , It will play the local animation . without , It will search the global animation manager and look for it there .
stay Phaser 3.50 Before , This method is called “delayedPlay”.

Parameters :
key character string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig Animation to play 、 Animation instance or PlayAnimationConfig Object's string based key .
delay Numbers The delay to wait before the animation starts playing ( In Milliseconds ).

this.add.sprite(...).playAfterDelay({
     key: 'shoot1', repeatDelay: 800 }, 800);

playReverse(key [, ignoreIfPlaying]) stay Sprite Play the animation backwards on the .

Phaser The animation in can belong to the global animation Manager , It can also be dedicated to this Sprite.
The benefits of global animation are multiple Sprite Can play the same animation , Without copying data . You only need to create it once , Then at any Sprite Just play on the .

key character string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig Animation to play 、 Animation instance or PlayAnimationConfig Object's string based key .
ignoreIfPlaying Boolean value < Optional >false If the animation is already playing , Then ignore this call .

mysprite.playReverse('walk');

reverse() Reverse the animation that has been played on the GameObject .

mysprite.anims.reverse();

anims This sprite's animation controller .

var mysprite = this.add.sprite(...)
mysprite.anims

getName() Returns the key of the currently loaded animation .

stay Phaser 3.50 Before , This method is called getCurrentKey

mysprite.anims.getName() 

isPaused :boolean true If the current animation is paused , otherwise false.

var ret = mysprite.anims.isPaused

yoyo :boolean yoyo:true The animation that will play backwards , From the end to the beginning , Then repeat or complete .yoyo:false The animation of the ball will only be played from beginning to end .

var ret = mysprite.anims.yoyo

isPlaying :boolean Whether the animation is currently playing

var ret = mysprite.anims.isPlaying

accumulator number Internal time overflow accumulator .

delta As update Part of the procedure , This will add time .

var ret = mysprite.anims.accumulator

nextTick :number The point in time at which the next animation frame will change .

The value and accumulator As update Part of the step .

var ret = mysprite.anims.nextTick

getProgress() mysprite.anims.getProgress;

Between a return 0 and 1 Between the value of the , Indicates the playback distance of this animation , Ignore repetition and yoyos. If the animation defines a non-zero repetition ,getProgress also getTotalProgress It will be different , because getProgress Does not include any repetition or repetition delay , Including getTotalProgress.

 this.catimg = this.add.sprite(400,300,'cat1');
 this.catimg.play('playcat');

this.catimg.anims.getProgress();

getName() Returns the of the currently loaded animation key.

 var mysprite = this.add.sprite(500, 536)
 mysprite.anims.getName()

playAfterRepeat(key [, repeatCount]) Wait for the last animation to complete repeatCount Number of times to repeat the cycle , Then start playing the given animation .

You can use it to ensure that there is no sharp jump between two sets of animation , That is, from idle animation to walking animation , Let them blend smoothly with each other .
If no animation is currently running , The given animation will begin immediately .
stay Sprite When playing animation on , It first checks to see if it is possible to Sprite Matching key found locally . If possible , It will play the local animation . without , It will search the global animation manager and look for it there .

Parameters :
key character string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig Animation to play 、 Animation instance or PlayAnimationConfig Object's string based key .
repeatCount Numbers < Optional >1 How many times should the animation be repeated before the next start ?

this.anims.create({
     key: 'idle', frames: [...], repeat: -1, repeatDelay: 500, frameRate: 18 });
this.anims.create({
     key: 'turn', frames: [...], frameRate: 12 });

const ripley = this.add.sprite(400, 300, 'alien').play('idle'); //  Play first idle,
ripley.anims.playAfterRepeat('turn'); //  When idle Finish the first time , Start repeat When playing  playAfterRepeat Inside , Play turn,

chain(key) Set up an animation or a group of animations , Play immediately after the last animation is completed or stopped .

When the last animation must enter “ Completed ” Status to occur , That is, complete all its repetitions 、 Delay, etc , perhaps stop Directly invoke the method on it .
An animation that is set to repeat forever will never enter the completion state .
You can link a new animation at any time , Include before the current animation starts playing 、 During or at the end of playback ( Through its animationcomplete event ).
Link animation is specific to GameObjects , This means that different GameObjects can have different linked animations , Without affecting the animation they are playing .
Call this method without parameters to reset the animation of all current links .
stay Sprite When playing animation on , It first checks to see if it is possible to Sprite Matching key found locally . If possible , It will play the local animation . without , It will search the global animation manager and look for it there .

key character string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig | Array .< character string > | Array .< Phaser.Animations.Animation > | Array.< Phaser.Types.Animations.PlayAnimationConfig > String based keys for the animation to be played , perhaps Animation example , Or a PlayAnimationConfig object , Or an array of them .

this.anims.create({
     key: 'idle', frames: [...], repeat: -1, repeatDelay: 500, frameRate: 18 });
this.anims.create({
     key: 'turn', frames: [...], frameRate: 12 });
this.anims.create({
     key: 'walk', frames: [...], repeat: -1, frameRate: 18 });

const ripley = this.add.sprite(400, 300, 'alien').play('idle'); //  Play first idle,
ripley.anims.playAfterRepeat('turn'); //  When idle Finish the first time , Start repeat When playing  playAfterRepeat Inside , Play turn,
ripley.anims.chain('walk'); // idle Cycle ,turn Value to play once , All right turn Play when playback stops walk

//  The following will not be played walk, because idle Will repeat , It doesn't stop .
const ripley = this.add.sprite(400, 300, 'alien').play('idle'); //  Play first idle,
ripley.anims.chain('walk'); // idle Cycle ,turn Value to play once , All right turn Play when playback stops walk

reverse() Reverse the animation that has been played on the GameObject . ( Play the animation backwards )

mysprite.anims.reverse(); 

resume( [fromFrame]) Resume playback of the paused animation and isPlaying Property is set to true. You can choose to tell it to start playing at a specific frame .

Parameters :
fromFrame Phaser.Animations.AnimationFrame < Optional >
Optional frame set before playback resumes .

mysprite.anims.resume();

pause([atFrame]) Pause the current ​​ Animate and put isPlaying Property is set to false. You can choose to pause it at a specific frame .

Parameters :
atFrame Phaser.Animations.AnimationFrame < Optional > Optional frame set after pausing animation .

mysprite.anims.pause();

restart( [includeDelay] [, resetRepeats]) Restart the current animation from scratch .

You can also choose to reset the delay and repetition counters .
Calling it will ANIMATION_RESTART Trigger the event immediately
If you includeDelay Then it will ANIMATION_START The event is triggered after the delay expires , otherwise , Playback will begin immediately .

includeDelay Boolean value < Optional >false Whether the delay value of animation is included when restarting .
resetRepeats Boolean value < Optional >false Whether to reset the repetition counter ?

mysprite.anims.restart();

playAfterRepeat(key [, repeatCount]) Wait for the current animation to complete repeatCount Number of times to repeat the cycle , Then start playing the given animation .

Wait for the current animation to complete repeatCount Number of times to repeat the cycle , Then start playing the given animation .
You can use it to ensure that there is no sharp jump between two sets of animation , That is, from idle animation to walking animation , Let them blend smoothly with each other .
If no animation is currently running , The given animation will begin immediately .
stay Sprite When playing animation on , It first checks to see if it is possible to Sprite Matching key found locally . If possible , It will play the local animation . without , It will search the global animation manager and look for it there .

Parameters :
key character string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig Animation to play 、 Animation instance or PlayAnimationConfig Object's string based key .
repeatCount Numbers < Optional > 1 How many times should the animation be repeated before the next start ?

chain(key) Set up an animation or a group of animations , Play immediately after the current animation is completed or stopped . Be careful not to use repeat Set to -1,

The current animation must enter “ Completed ” Status to occur , That is, complete all its repetitions 、 Delay, etc , perhaps stop Directly invoke the method on it .
Set to repeat:-1 Your animation will never go to completion .
You can link a new animation at any time , Include before the current animation starts playing 、 During or at the end of playback ( Through its animationcomplete event ).
Link animation is specific to GameObjects , This means that different GameObjects can have different linked animations , Without affecting the animation they are playing .
Call this method without parameters to reset the animation of all current links .
stay Sprite When playing animation on , It first checks to see if it is possible to Sprite Matching key found locally . If possible , It will play the local animation . without , It will search the global animation manager and look for it there .

Parameters :
key character string | Phaser.Animations.Animation | Phaser.Types.Animations.PlayAnimationConfig | Array .< character string > | Array .< Phaser.Animations.Animation > | Array.< Phaser.Types.Animations.PlayAnimationConfig >
String based keys for the animation to be played , perhaps Animation example , Or a PlayAnimationConfig object , Or an array of them .

setName(value)

Set up name Properties of this GameObject and return this GameObject for further links . The name Property is not defined by Phaser fill , For your own use only .

this.load.image('apple', 'assets/sprites/apple.png');
this.add.sprite(200, 300, 'apple').setName('apple1');
var sprite = this.add.sprite(400, 300, 'apple').setName('apple2');

console.log(sprite.name) // apple2
原网站

版权声明
本文为[Durian is not delicious]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202280552463773.html