phaser create animation from canvas texture
 preload ()
    {
        const framesPerRow = 8;
        const frameTotal = 32;

        //  Create a CanvasTexture that is 256 x 128 in size.
        //  The frames will be 32 x 32, which means we'll fit in 8 x 4 of them to our texture size, for a total of 32 frames.
        const canvasFrame = this.textures.createCanvas('dynamicFrames', 256, 128);

        let radius = 0;
        const radiusInc = 16 / frameTotal;

        let x = 0;
        let y = 0;
        let ctx = canvasFrame.context;

        ctx.fillStyle = '#ffff00';

        for (let i = 1; i <= frameTotal; i++)
        {
            //  Draw an arc to the CanvasTexture
            ctx.beginPath();
            ctx.arc(x + 16, y + 16, Math.max(1, radius), 0, Math.PI * 2, false);
            ctx.closePath();
            ctx.fill();

            //  Now we add a frame to the CanvasTexture.
            //  See the docs for the arguments.
            canvasFrame.add(i, 0, x, y, 32, 32);

            x += 32;
            radius += radiusInc;

            //  Hit the end of the row? Wrap it around.
            if (i % framesPerRow === 0)
            {
                x = 0;
                y += 32;
            }
        }

        //  Call this if running under WebGL, or you'll see nothing change
        canvasFrame.refresh();

        //  Display the whole of our freshly baked sprite sheet
        this.add.image(0, 0, 'dynamicFrames', '__BASE').setOrigin(0);

        //  Let's create an animation from the new frames
        this.anims.create({
            key: 'pulse',
            frames: this.anims.generateFrameNumbers('dynamicFrames', { start: 1, end: frameTotal }),
            frameRate: 28,
            repeat: -1,
            yoyo: true
        });

        //  Add a bunch of Sprites that all use the same base texture and animation
        for (let i = 0; i < 50; i++)
        {
            const ball = this.add.sprite(8 + i * 16, 164, 'dynamicFrames').play('pulse');

            this.tweens.add({
                targets: ball,
                y: 584,
                duration: 2000,
                ease: 'Quad.easeInOut',
                delay: i * 30,
                yoyo: true,
                repeat: -1
            });
        }
    }
Source: github.com

Javascript相关代码片段

json string to object jQuery

Easy Data fetching in React

disable rule jsx-a11y/label-has-for

react-native-confirmation-code-field

reset select2 in bootstrap modal

nodejs export and import

mui datagrid rows per page

objs.sort() js

full calendar angular

replace all empty lines with regex javascript

create json jquery

mysql docker ER_NOT_SUPPORTED_AUTH_MODE

switch case in js

hide button after click react

edit xlsx file on nodejs without losing styling

chart js tooltip not showing

how to do hello world in python

javascript standard deviation

enter button submit from react

loop in formarray

bridging react native and native

gsap splittext alternative

jenkins nodejs

expo 50 nav bar

load npm to browser

moment-timezone

currency formatter js

image to text react native

Nodejs image uploader

jquery check if in viewport

parallax effect download js

jsx Nextjs, dashboard, kazi, zobaidul kazi

expect function to throw error vite/jest

react toastify promise

make.com arrays

react flex

javascript object.fromentries

format json without quotes

wordpress page keeps reloading

nodelist javascript

angular refresh page after submit

unminify js

jquery class contains text

ajax to controller not mapping list of ints

pdf.js shortcode

js length of string

ng build prod not working

or truth table

js or symbol

Git - Ignore node_modules folder everywhere

.net and javascript date functions format

js element in viewport

object detection in react native

remove repeated elements in array javascript

useTransission react

custom cursor for react

react get blue outline on routing Links

get rid of blue button effect on react links

nextjs remote url image

react router v6 basic code

lua table to json online

download video from url javascript

jquery set max length input

JS not selecting the element

react native clock

shadcn toast not showing

express folder structure

audio element

javascript set display of elem to block

react phone number input

tailwind intellisense not working with react

cannot find name 'cy'

submit form react

footer react bootstrap

angular interview questions and answers

trigger alert if button is clicked

change query params

verify control code iban javascript

react-spring

Next JS solve the Hydration error