PIXI.JS新手,正在寻求有关TextureCache的建议和疑难解答,加载程序问题

问题描述 投票:0回答:1

我冒险进入PIXI和JS的世界,对我来说是一种新的编程语言,喜欢现在的样子,但是我遇到了问题。

我对TextureCache和加载器有些困惑。如果您查看我的代码的一部分,我会尝试在屏幕上添加3个不同的图像。我一直在关注pixi网站的“入门”部分。我想添加他们拥有的猫图像,tileset图像(全部)*,然后添加tileset图像的图块。

问题是,我创建了3个新的Sprite实例,当我希望它显示整个tileet时,tileset图像显示了tile(rocket)的区域ive集。我已经在cahce和加载器中加载了图块。

为什么图块显示裁切后的图像而不显示整个图像?我是否正确使用缓存来存储图像?我是否使用正确的资源方法从缓存或加载器中定位图像?缓存中有什么要点吗?

我的想法**当您使用矩形方法时,它会破坏原始图像,并且裁剪后的版本现在为tileet1(我的图像的名称)?

<html>
<body>

<script src="pixi.js"></script>

<script>
//Aliases
let Application = PIXI.Application,
    loader = PIXI.loader,
    resources = PIXI.loader.resources,
    Sprite = PIXI.Sprite,
	Rectangle = PIXI.Rectangle,
	TextureCache = PIXI.utils.TextureCache;
	

let app = new PIXI.Application({ 
    width: 1000, 
    height: 600,                       
    antialias: true, 
    transparent: false, 
    resolution: 1
  }
);

//Add the canvas that Pixi automatically created for you to the HTML document
document.body.appendChild(app.view);
TextureCache["tileset1.png","images/3.png"];
//load an image and run the `setup` function when it's done
loader.add(["images/3.png","tileset1.png"]).load(setup);

//This `setup` function will run when the image has loaded
function setup() {
	let texture = TextureCache["tileset1.png"];
	let rectangle = new Rectangle(96,64,32,32);
	texture.frame = rectangle;
	

  //Create the cat sprite, use a texture from the loader
  let card = new Sprite(resources["images/3.png"].texture);
  let tile = new Sprite(resources["tileset1.png"].texture);
  let rocket = new Sprite(texture);
  
  card.scale.set(0.06,0.06);
  
  tile.x=400;
  tile.y=400;
  
  rocket.x=100;
  rocket.y=100;
  
  //Add the cat to the stage
  app.stage.addChild(card);
  app.stage.addChild(tile);
  app.stage.addChild(rocket);
  
  app.renderer.render(app.stage);
}

</script>
</body>
</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pixi.js/5.2.4/pixi.js"></script>
javascript textures sprite loader pixi.js
1个回答
0
投票

Is there any point of the cache?-这个问题似乎对您的问题最重要:)

例如,搜索“ pixi.js”和“ TextureCache”会给出以下答案:

TLDR:通常不应该使用TextureCache:)

© www.soinside.com 2019 - 2024. All rights reserved.