Jump to content

Cordova builds crash when using this.anims.play method


venpresath
 Share

Recommended Posts

I am currently trying to bundle and run my game on Cordova. 
It works perfectly in the browser, but whenever it is that I run any kind of this.anims.play method, I get an error saying "JavaScript error: main.js:1: TypeError: undefined is not an object (evaluating 't.frame')" in my console. 

It's probably worth noting that I am using TexturePacker and a sprite atlas.
 

//PLAYER SCRIPT

import { Physics } from 'phaser';

import Helpers from '../helpers/helpers';

export default class extends Physics.Arcade.Sprite {
  constructor(scene, x, y, texture) {
    super(scene, x, y, texture);

    scene.add.existing(this);
    scene.physics.add.existing(this);
    scene.physics.world.enable(this);
    //For debugging
    this.setCollideWorldBounds(true);

    this.direction = 0;
    this.facingRight = false;
  }

  create() {
    let playerAnims = [
      {
        frameName: "run",
        start: 0,
        end: 5,
        frameRate: 10,
        repeat: -1
      },
      {
        frameName: "jump",
        start: 0,
        end: 2,
        frameRate: 10,
        repeat: -1
      },
      {
        frameName: "fall",
        start: 0,
        end: 3,
        frameRate: 10,
        repeat: -1 
      },
      {
        frameName: "idle",
        start: 0,
        end: 1,
        frameRate: 0,
        repeat: -1
      },
    ];
//This is something I extracted from the class to generate scenes.
//Adding the method back into the class does not change anything. 
//I posted this code below in case it MIGHT cause an issue. Which it shouldn't. 
    Helpers().generateAnimations(playerAnims, this.scene, this.texture.key);
    this.setSize(16, 40).setOrigin(1).setScale(2).setOffset(8, 24)
  }

  update(keys) {
    // this.setSize(16, 40).setOrigin(1).setScale(2).setOffset(8, 24)

    this.direction = keys.D.isDown - keys.A.isDown;
    this.setVelocityX(this.direction * 100);
    //Set facing
    if (keys.A.isDown) this.facingRight = false;
    if (keys.D.isDown) this.facingRight = true;

    this.flipX = !this.facingRight;

    if (this.direction) {
      // this.anims.play("run", true);
      this.setVelocityX(this.direction * 100)
    } else {
      this.setVelocityX(0)
      // this.anims.play('idle', true);
    }

    //The last part of this should be changed to this.body.touching.down...
    //However, that doesn't work on collideWorldBounds
    if (keys.SPACE.isDown && this.body.velocity.y === 0) {
      this.setVelocityY(-100);
    }
    if(this.body.velocity.y < 0){
      // this.anims.play('jump');
    } else if(this.body.velocity.y > 0){
      // this.anims.play('fall');
      // -_- ...ugh
      // this.setSize(this.frame.cutWidth, this.frame.cutHeight, false).setOffset(this.frame.x, this.frame.y).setOrigin(1);
    }
  }

}







###################### GENERATE FRAMES AND HELPER FUNCTIONS ################


//An assorted assortment of helpful helper functions to help you clean up your classy classes.

export default function Helpers(){
  let generateAnimations = (frames, scene, textureKey) => {
  frames.forEach(frame => {
    const generatedFrames = scene.anims.generateFrameNames(textureKey, {
      start: frame.start,
        end: frame.end, prefix: `${frame.frameName}/0`, suffix: '.png'
      });
      scene.anims.create({
        key: frame.frameName,
        frames: generatedFrames,
        frameRate: 10,
        repeat: frame.repeat
      });
    });
  }

  return({
    generateAnimations
  })
}

 

Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...