Jump to content

How to use sprite sheet with MovieClips?


Recommended Posts


I'm banging my head against the desk try to get spritesheets working in PixiJS.  When I began the project, v3 was still current so I'm hoping to stick to that version just to get this project out the door.

So, rather than use a JSON file, I'm opting to just loop through creating frames from a single image.  I've already found a few posts here and elsewhere on how to do it, but the end result is not working.  I'm scratching my head as to what I'm missing.  All I get is the first frame.

I'm loading all textures using the PIXI Loader then basically using this script:

var base = PIXI.utils.TextureCache[ "img/spritesheet.png" ];

var aryTextures = [];

var frameWidth = 525;
var frameHeight = 700;

var i = 0;
var length = 12;

var col;
var row;
var colMax = 12;

for ( i; i < length; i++ ) {

	row = Math.floor( i / colMax );
	col = i - row * colMax;

	var texture = new PIXI.Texture( base );
	var rect = new PIXI.Rectangle( frameWidth * col, frameHeight * row, frameWidth, frameHeight );
	texture.frame = rect;

	aryTextures.push( texture );


var mc = new PIXI.extras.MovieClip( aryTextures );
mc.loop = false;
mc.onComplete = function() { /*do stuff*/ };
myStage.addChild( mc );

mc.gotoAndPlay( 0 );

Still on my first project with PixiJS, so sorry for my noobiness!


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.

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.


  • Recently Browsing   0 members

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