Code Monkey home page Code Monkey logo

Comments (6)

jareguo avatar jareguo commented on May 14, 2024

Thanks ggarek, this is a bug, and I hadn't noticed.

from cocos-engine.

jareguo avatar jareguo commented on May 14, 2024

Wait, this is by design, not a bug. Only assets under assets/resources directory will be copied.
Please try:

var url = cc.url.raw("resources/particles/1.plist");
particleSystem.file = url;

from cocos-engine.

ggarek avatar ggarek commented on May 14, 2024

@jareguo I created new project from scratch to check it once again. I think there is a though, let me put some more details about it.

First of all, this thing is not correct

var url = cc.url.raw("resources/particles/1.plist");

because the cc.url.raw adds the relative path prefix to the resources in runtime, so you need only pass a path to a specific resource you need relative to your assets/ folder within Cocos Creator.
So if you have

-- assets
  -- textures
    -- mytexture.png

then to get the correct url to mytexture.png you need to make this call:

var url = cc.url.raw("textures/mytexture.png");

Regarding the bug.

I create a project, add particle resource, then drag the particle file to the scene in Cocos Creator. In this case both files (.plist and .png) are copied to the build directory.

But, when i add a particle to Assets in Cocos Creator, then i create the ParticleSystem in runtime, like this:

start: function () {
        const node = new cc.Node();
        const ps = node.addComponent(cc.ParticleSystem);
        ps.file = cc.url.raw('/particles/fire-parts.plist');
        node.setPosition(200, 200);
        cc.director.getScene().addChild(node);
    },

It works in development mode, but when i build the project, the .plist file is absent in the output directory. The .png file though is copied.

Here is the assets dir listing:

➜  cc-particles-not-copied ls -al assets/particles
total 64
drwxr-xr-x  10 garek  staff   340 Apr 18 13:10 .
drwxr-xr-x  11 garek  staff   374 Apr 18 12:56 ..
-rw-r--r--   1 garek  staff  2463 Apr 18 12:47 fire-parts.plist
-rw-r--r--   1 garek  staff    88 Apr 18 12:47 fire-parts.plist.meta
-rwxr-xr-x   1 garek  staff   622 Apr 18 12:47 fire.png
-rw-r--r--   1 garek  staff   633 Apr 18 12:47 fire.png.meta
-rw-r--r--   1 garek  staff  2872 Apr 18 12:45 meteor-tail.plist
-rw-r--r--   1 garek  staff    88 Apr 18 12:45 meteor-tail.plist.meta
-rw-r--r--   1 garek  staff  1210 Apr 18 12:45 particle2.png
-rw-r--r--   1 garek  staff   636 Apr 18 12:45 particle2.png.meta

And here is the build dir listing:

➜  cc-particles-not-copied ls -al build/web-desktop/res/raw-assets/particles
total 24
drwxr-xr-x  5 garek  staff   170 Apr 18 13:11 .
drwxr-xr-x  4 garek  staff   136 Apr 18 13:11 ..
-rwxr-xr-x  1 garek  staff   622 Apr 18 13:11 fire.png
-rw-r--r--  1 garek  staff  2872 Apr 18 13:11 meteor-tail.plist
-rw-r--r--  1 garek  staff  1210 Apr 18 13:11 particle2.png

As you can see, fire.png file is present, but fire-parts.plist is not.

from cocos-engine.

jareguo avatar jareguo commented on May 14, 2024

But, when i add a particle to Assets in Cocos Creator, then i create the ParticleSystem in runtime
It works in development mode, but when i build the project, the .plist file is absent in the output directory. The .png file though is copied.

As mentioned above, only assets under assets/resources directory will be copied to the output directory.

from cocos-engine.

ggarek avatar ggarek commented on May 14, 2024

Ok, i tried to put the .plist and .png which i use to create ParticleSystem dynamically under assets/resources and it is now copied during the build process. Thanks, now i get what you meant.

Still it seems not very convenient. If i create a node via editor then the resource files are copied to the build directory no matter the path, but if i do it dynamically, then i need to put it under a specific path.
But i guess, it may change through the versions, or there will be a hint so everybody know the name convention.

Anyways, thanks for the explanation!

from cocos-engine.

jareguo avatar jareguo commented on May 14, 2024

Yes there will be a hint in the future, thanks for the feedback ~~~

from cocos-engine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.