设为首页收藏本站同能贴吧 切换语言 繁体中文
开启辅助访问 切换到窄版
扫描二维码关注官方公众号
返回列表
+ 发新帖
查看: 89|回复: 0

[转载发布] Iavra Particle Engine

[复制链接]
累计送礼:
0 个
累计收礼:
1 个
  • TA的每日心情
    开心
    2026-7-12 04:10
  • 签到天数: 209 天

    连续签到: 2 天

    [LV.7]常住居民III

    8305

    主题

    864

    回帖

    3万

    积分

    管理员

    Rank: 9Rank: 9Rank: 9

    VIP
    7
    卡币
    30617
    OK点
    16
    推广点
    0
    同能卷
    50
    积分
    39816

    灌水之王

    发表于 6 天前 | 显示全部楼层 |阅读模式
    Plugin


            Particle Engine - Core


    Description


            Extensible particle engine, that creates effects by applying behaviours to particle objects.


    Author


            Iavra


    How to Use


            The following script call creates a sample emitter, that displays a bunch of particles wandering around the screen:



    var emitter = new IAVRA.PARTICLE.Emitter()
            .setCounter({
                    start: function(emitter) {},
                    update: function(emitter) { return 1; }
            })
            .addBehaviour({
                    setup: function(emitter, particle) {
                            particle.texture = PIXI.Texture.fromImage('img/particle.png');
                            particle.position.set(Graphics.width / 2, Graphics.height / 2);
                            particle.life = 200;
                    },
                    update: function(emitter, particle, index) {
                            particle.velocity.x += Math.random() - 0.5;
                            particle.velocity.y += Math.random() - 0.5;
                    }
            });


                    As you can see, after creating the emitter itself, we are adding two properties to it: A counter and a behaviour.


            Counters regulate the emission rate and instruct the emitter, how many new particles it has to create at any given time. In our example, we create 1 new particle every frame and no extra particles, when the emitter starts. Each emitter can only have 1 counter and defaults to a dummy instance, that causes no particles to be created.


             


            Behaviours control, how particles are created and updated, how the look and interact with each other and their surroundings. They are powerful, but can get very complex. In our example, we assign a texture to the particle and set its starting position to the center of the screen. During each update, it will accelerate in a random direction and increase its age counter by 1, before finally dying after 200 updates. Each emitter can have any number of behaviours assigned and they are executed in the order they were added.


             


            Now, the only thing left to do is to start the emitter and add it to the scene. The Emitter class contains a number of functions to interact with emitters and each of them returns the emitter itself, so they can be chained:



    emitter.start();                 Starts the emitter. Before calling this function, it will simply do nothing.
    emitter.stop();                  Stops the emitter, causing all particle creation and updating to stop.
    emitter.resume();                Resumes the emitter, after it has previously been stopped.
    emitter.skip(count);             Fast forwards a number of update cycles. Creates and updates particles accordingly.
    emitter.clear();                 Removes all current particles from the emitter.
    emitter.setCounter(counter);     Sets the counter to be used. Needs to implement "start" and "update" functions.
    emitter.setFactory(factory);     Replaces the default particle factory. Needs to implement "create" and "dispose".
    emitter.addBehaviour(...b);      Adds one or more behaviours to the emitter.
    emitter.removeBehaviour(b);      Removes all occurences of a given behaviour from the emitter.
    emitter.removeAllBehaviours();   Removes all behaviours from the emitter.


            Adding or removing behaviours while the emitter is running, affects both new and existing particles, so keep that in mind. Inside a behaviour, the following properties of the particle can be accessed:

                    Code:       
    1. texture        (PIXI.Texture)    Image to be displayed for the particle. If this is not set, you won't see anything.
    2. life           (number)          The particle's lifespan. Defaults to Infinity.
    3. age            (number)          Read-only. Starts at 0 and can be used to track the particle's age.
    4. dead           (boolean)         If this gets set to true, the particle will be disposed by the emitter.
    5. oldPosition    (PIXI.Point)      Read-only. Gets set to the particle's position before the last update.
    6. position       (PIXI.Point)      The particle's current position. Automatically gets updated every update.
    7. velocity       (PIXI.Point)      Marks the rate, at which the particle's position changes.
    8. scale          (PIXI.Point)      Scaling factor of the particle. Its x and y value should be kept synchron.
    9. radius         (number)          Gets used by some behaviours to implement collision.
    10. alpha          (number)          Handles the particle's transparency on a scale from 0 (transparent) to 1 (opaque).
    11. rotation       (number)          The particle's rotation around its center point, in radians.
    12. tint           (number)          Tinting color of the particle, as hex number. 0xFFFFFF removes all tinting.
    13. blendMode      (number)          Blend mode to be used. Support variies between renderers. Default is 0.
    复制代码





    Terms of Use


            Free to use for both commercial and non-commercial games. Please give credit.


    Download


    http://pastebin.com/ss7T05b0


    Changelog


            v1.00 - First version of the engine.


            v1.01 - Revamped the engine structure by (re)introducing behaviours.


            v1.02 - Moved particle aging from behaviours into the emitter.


            v1.03 - Introducing activities, which run during each update, but before particles are updated.


            v1.04 - Added a way for behaviours to store and read data on a particle.


    本贴来自国际rpgmaker官方论坛作者:Iavra处,因国际论坛即将永久关站,为了存档多年珍贵资料,署名转载到本论坛存档,由于官方帖子为英文原帖,需要中文翻译请点击论坛顶部切换语言为中文就可以将帖子翻译成中文浏览,方便大家随时查看,原文地址:https://forums.rpgmakerweb.com/threads/iavra-particle-engine.55741/
    天天去同能,天天有童年!
    回复 送礼论坛版权

    使用道具 举报

    文明发言,和谐互动
    文明发言,和谐互动
    高级模式
    您需要登录后才可以回帖 登录 | 立即注册

    本版积分规则

    简体中文
    繁體中文
    English(英语)
    日本語(日语)
    Deutsch(德语)
    Русский язык(俄语)
    بالعربية(阿拉伯语)
    Türkçe(土耳其语)
    Português(葡萄牙语)
    ภาษาไทย(泰国语)
    한어(朝鲜语/韩语)
    Français(法语)
    关闭

    幸运抽奖

    社区每日抽奖来袭,快来试试你是欧皇还是非酋~

    立即查看

    聊天机器人
    Loading...

    QQ|Archiver|手机版|小黑屋|同能RPG制作大师 ( 沪ICP备12027754号-3 )

    GMT+8, 2026-8-1 20:43 , Processed in 0.134474 second(s), 55 queries .

    Powered by Discuz! X3.4

    Copyright © 2001-2020, Tencent Cloud.

    快速回复 返回顶部 返回列表