davidfig / pixi-cull

a library to visibly cull objects designed to work with pixi.js
MIT License
112 stars 15 forks source link

Cannot read property 'x' of undefined #1

Closed PhilippHandle closed 5 years ago

PhilippHandle commented 5 years ago

Hi, currently I'm getting started with pixi and your plugins. I tried to get your example up and running, but I can't get this to work

Pixi v4.8.5 + culling + viewport game.js is a combined js with pixi.js + bundle version of cull and viewport

var app = new PIXI.Application();
document.body.appendChild( app.view );

// create viewport
var viewport = new PIXI.extras.Viewport( {
    screenWidth : window.innerWidth,
    screenHeight : window.innerHeight,
    worldWidth : 10000,
    worldHeight : 10000
} );

app.stage.addChild( viewport );
viewport.drag().pinch().wheel().decelerate();

// add red boxes
for( var i = 0; i < 1; i++ ) {
    var sprite = viewport.addChild( new PIXI.Sprite( PIXI.Texture.WHITE ) );
    sprite.tint = 0xff0000;
    sprite.width = sprite.height = 100;
    sprite.position.set( Math.random() * 10000, Math.random() * 10000 );
}

var cull = new PIXI.extras.Cull.Simple();
cull.addList( viewport.children );
cull.cull( viewport.getVisibleBounds() );

getting the error

game.js:45938 Uncaught TypeError: Cannot read property 'x' of undefined
    at Simple.cull (game.js:45938)
    at game.js:46990
cull @ game.js:45938
(anonymous) @ game.js:46990

-->

object[this.visible] = box.x + box.width > bounds.x && box.x < bounds.x + bounds.width && box.y + box.height > bounds.y && box.y < bounds.y + bounds.height;

thanx for your help

davidfig commented 5 years ago

Thanks for the report. There was a bug in the options.calculatePIXI that's now fixed in v0.3.0. I also tweaked the sample code in README.md so it continues to cull as you move the viewport. Let me know if you see any other issues.

PhilippHandle commented 5 years ago

thanks! I will play with it this weekend!