Loading resources in javafx

Source: Internet
Author: User
Tags ftp file

There are some path problems when loading resources in javafx.

Resource loading in game development is nothing more than audio, images, and fonts.


While loading images in javafx uses relative paths and SRC folders.

For example, if you want to download player.png in the resfile folder under src, we only need new image ("Res/player.png ").

However, you cannot load the audio. If the new audioclip ("Res/battleworkflow") is used to load the audio, the URI. getscheme () = NULL is displayed. Obviously, this tells you that no protocol is specified. The protocol here is not tcp udp. But http ftp file.


Therefore, when loading audio, you can use the getclass (). getresource ("XXXXX"). tostrin. G () method to obtain the path of resources in the same directory of the class. You can also use thread. currentthread (). getcontextclassloader (). getresource ("XXXXX"). tostring () to obtain resources in the src directory.


The font is the same as the audio. Of course, loading images in this way is equally effective.


Reprinted please indicate the source: http://blog.csdn.net/ml3947

----------------------------------------------------------------------------

Javafx-based game engine under development...

The progress is not bad, but some examples of games are also being done.

A separate website will be created later.

----------------------------------------------------------------------------


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.