Comments (6)
+1 I seem to be having the same issue when trying to remove a child that was definitely added to the appropriate stage.
from pixijs.
Hi There! Very interesting indeed! I'm pretty sure that the remove child function works OK as its fairly simple. When it throws that error its because the child is not in the children array:
PIXI.DisplayObjectContainer.prototype.removeChild = function(child)
{
var index = this.children.indexOf( child );
if ( index !== -1 )
{
// remove child code
}
else
{
throw new Error(child + " The supplied DisplayObject must be a child of the caller " + this);
}
}
It could be the case that you are removing the item twice in your destroy function? I have accidentally done this a few times myself :P
If you guys dont mind sharing you code I would be more than happy to take a look and see if it is pixi.js that is playing up.
Another way to check is to see if the stage contains the display object before removing. I will add this to the master build but for now this code snippet might help (add it to your codebase after importing pixi.js file):
PIXI.DisplayObjectContainer.prototype.contains = function(child)
{
return (this.children.indexOf( child ) !== -1);
}
You will be able to go
// will return true if is child otherwise false
var isChild = Stage.contains(displayObject)
from pixijs.
@GoodBoyDigital you were right. I was calling it twice! Sorry...
from pixijs.
This is working for me now. I was containing my objects in a plain array, and was trying to keep the two in sync. However, when I just use the stage itself as a container, everything works fine.
I am fairly new to game development, so maybe you can offer some insight on the best way to keep track of objects or sprites in Pixi. Basically any collection of entities. Would you suggest having only one stage and then having DisplayObjectContainers for each collection? For example, things like, bullets, explosions, enemies, particles, etc.
I am used to just keeping track of everything with plain JavaScript, so switching over to the structure of Pixi (which is WAY better) is just a little confusing. I am sure all of this will make a lot more sense once full game demos with source code get posted for studying purposes, such as run pixi run ;)
from pixijs.
samueller, no worries! If I had a penny for every time I did that I would be a man of moderate wealth ;)
jackrugile, for run pixi run I did exactly what you are doing. I keep an plain old array to store game elements. An array for enemies, an array for pickups etc.
Pixi.js isnt really a game engine, its main purpose is to render things to the screen (which is definitely useful for games though!) So your current plan of keeping your game logic separated from the rendering logic is definitely the way to go!
We are working on a little game to share with everyone. Hopefully it will help people understand the best way to use pixi.js :)
from pixijs.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from pixijs.
Related Issues (20)
- Feature Request: caching bitmap fonts in client? HOT 11
- Bug: Cannot read property 'getExtension' of undefined
- Bug: [v8] `text.style.fill === null` when `TextStyle` is reused instead of `TextStyleOptions` HOT 2
- Bug: [v8] BpuBufferSystem.onBufferDestroy contains null gpuBuffer when destroying via react hook HOT 3
- Bug: [v8 regression] pointerevents can drastically cut performance HOT 2
- Is there a way to simulate 3d projection/rotation in Pixi v8
- Bug: [v8.0.2] Sprite not updated correctly when its texture's frame is changed HOT 1
- Bug: [v8 regression] `Container.destroy()` is very slow on crowded containers HOT 3
- Bug: Publishing v7.x doesn't update latest dist-tags
- Bug: [v8 regression] moving a crowded `Container` drastically cuts performance HOT 8
- Bug: [v8] When adding `onRender` to a class extension, it does not work as expected
- Feature Request: [v8] Is there any way to pass a canvas instance to the new WebGLRenderer? HOT 2
- Bug: export image empty on firefox
- Bug: v8 Using webcam stream as source errors in Chrome
- Bug: [v8] passing `fill(0)` or `fill(0x000000)` to graphics shows white instead of black
- Q: [v8] Should release `@pixi/unsafe-eval@8`? HOT 3
- Bug: [v8] The filter is not taking the RenderTexture's frame's offset into account when being applied HOT 1
- Bug: Fill hex for black produces unpredictable results HOT 1
- Bug: Could not render app.canvas to normal canvas correctly in Windows chrome
- Bug: roundPixels=true causing precision issues HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pixijs.