mrxj88

cant get tilePosition of undefined

Recommended Posts

hey guys took a long break from phaser and decided to come back to mess around with it but oh man i must be stuck on something that is so simple but i cant figure it out.

i keep getting the error: cant get tilePosition of undefined. code is below. Thanks in advance! 

var background, playerR, run;
var playState = {
    
    create: function() {
        
        game.add.image(0, 0, 'background');
        
        playerR = game.add.image(200, 400, 'playerR');
        playerR.scale.setTo(1.8, 1.8);
        run = playerR.animations.add('run');
        playerR.animations.play('run', 10, true);
        
        
    },
    
    
    update: function() {
        
     background.tilePosition.x += 2;
        
    }

     
};

 

Share this post


Link to post
Share on other sites
4 hours ago, lewster32 said:

You haven't defined background, only initialised it. I assume the first line of the create function needs to be:


background = game.add.image(0, 0, 'background');

 

Thanks for the reply but I have tried that but it still gives me the same error. I'm assuming it has to do with me using states for the first time .  It's gotta be some small error. Any other ideas

Share this post


Link to post
Share on other sites

I figured it out. I was supposed to add it as a tileSprite instead of add.image to have it to work. just figured i put that out there if anybody else had the same problem.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now


  • Recently Browsing   0 members

    No registered users viewing this page.