Jump to content

Preloader


royibernthal
 Share

Recommended Posts

I'm trying to create a preloader for my game.

 

I figured I'd have to make 2 states:

 

PreloaderState - I load the preloader sprite so it can appear in GameState, when loaded I move to GameState.

GameState - In preload() I set the preloader sprite I loaded in PreloaderState.

 

However when I try to CREATE the preloader sprite the whole screen turns black (an error occured), without creating a preloader sprite everything works fine and the game is started.

 

Is it not possible to add a sprite instance to the game in a state's preload()?

 

What am I doing wrong?

 

Here are the states:

 

/*Preloader State*/var PreloaderState = function(game) {};PreloaderState.prototype.preload = function(){game.load.image('preloader', 'images/preloader.jpg');};PreloaderState.prototype.create = function(){game.state.start('game');}/*Game State*/var GameState = function(game) {};GameState.prototype.preload = function(){var preloader = game.sprite.add(0, 0, 'preloader'); //Creates an error, code after this line is not reachedgame.load.setPreloaderSprite(preloader);}
Link to comment
Share on other sites

xdiepx - right, a stupid mistake on my behalf. Another one I noticed - I wrote setPreloaderSprite when it should be setPreloadSprite. Fixed.

 

Pedro Alpera and rich - I was not aware of the existence of templates actually, it helped me realize many other things about structure and features I wasn't aware of, thanks.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

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