So I'm trying to splice all frames from an image, convert them to textures then put them into an array but I'm not sure as to why it is erroring, also I am also not sure why the if statements need to be above the "let rect" declarations
let createArrayTexture = function(source, frameWidth, frameHeight){
let textureArray = [];
let frameX = 0;
let frameY = 0;
let totalFrames = PIXI.loader.resources[source].texture.width/32 * PIXI.loader.resources[source].texture.height/32;
for(let i = 0; i <= totalFrames; i++){
console.log(`${i}, frameX: ${frameX} frameY: ${frameY}`);
let tempTexture = new PIXI.Texture(PIXI.utils.TextureCache[source]);
if(frameX === PIXI.loader.resources[source].texture.width){
frameX = 0;
frameY+=32;
}
if(frameY === PIXI.loader.resources[source].texture.height){
return;
}
let rect = new PIXI.Rectangle(frameX, frameY, frameWidth, frameHeight);
tempTexture.frame = rect;
textureArray.push(tempTexture);
frameX+=32;
//console.log(tempTexture);
}
return textureArray;
};
let createPlayer = function(){
let animationArray = createArrayTexture("./img/player.png", 32, 32);
let frameFlipChar = new PIXI.extras.AnimatedSprite(animationArray);
};