Babylon.js disable frustum culling for SolidParticleSystem? - particle-system

I'm attempting some simple data viz of a point cloud. My scene contains nothing but a 40K particle SolidParticleSystem and a small ground plane used for a visual reference when moving the camera. Every time world 0,0,0 goes out of the view frustum (by rotating or moving the camera), the entire SolidParticleSystem ceases to render.
It took me a long time to figure out why my particles kept disappearing for no apparent reason, until by trial and error of moving the camera around I figured out what was going on. The reference plane continues to render as expected.
Is it possible to defeat this behavior?

It is:)
Just call mesh.alwaysSelectAsActiveMesh = true and this way the frustum test will be disabled

Related

Cocos2D-X nodes loading in wrong positions have RemoveAllChildren()

I'm only using one scene object for my entire 2d sidescrolling platformer with two layers: There is a hudLayer for the controller, and the gameLayer for everything in the game.
When I control my character to walk into a door (sprite with a physicsBody that has a callback that takes me to the next level), the next level loads by these instructions:
remove all event listeners
stop all actions for both layers (the gameLayer typically has been doing a Follow action that follows the player, and is limited to the size of the backgroundSpriteNode)
remove all children from the gameLayer
set gameLayer position to Vec2(0,0)
load level 2 (a complete copy of what level 1 should look like... load the background sprite to gameLayer, playerSprite, add event listeners)
add event listeners back to the hudLayer
The only problem is that for whatever reason, the level only partially loads the way it should... For instance, coins appear in the spots they should, but platforms don't seem to. Neither that or the player, or other characters. Not sure really why these objects are specifically not loading in the correct positions, but maybe someone who has experienced this sort of problem before can help?
Most nodes (such as platforms) are appearing below the bottom of the screen when they should be fully shown at the bottom of the screen. Characters are appearing down there too when they should be appearing above the platforms.
P.S. After testing a bit more, I've come to realize that SOMETIMES some of the platforms are loading in the correct positions, but sometimes they aren't. Not sure why. A fix for this may be to load things one at a time with a delay between them. But I'd rather not have to put delays and just figure out what the deal is.
Figured it out: for whatever reason, I needed to add a delay in there. I think for whatever reason, by calling removeAllChildren(), something got messed up with the positions. It was my suspicion since SOME of the time, parts of the next level would load, but only some parts, and only sometimes.
Here's the code I added to run an action on the gameLayer once all children were removed, etc...
runAction(Sequence::createWithTwoActions(DelayTime::create(0.1), CallFunc::create( [&] ( ) {
loadLevel2(this);
})));

How to re-spawn particles randomly in Away3D

I'm attempting to create a particle effect using Sparticle and Away3d. The effect is a little burst of bubbles that float up to the top of the screen when items are clicked.
I have the effect loaded and working and it looks good, but unfortunately the effect always spawns the bubbles with the same random velocities each time. The velocities seem to be set when the animation first runs and then never changes.
How do I restart the animation with new velocities each time?
I've tried calling stop and start on the animator, and resetTime but I suspect it's just moving the time back to 0 and that's why the animation isn't actually restarting properly.
i.e.
particleGroup.animator.stop();
particleGroup.animator.start();
The reset method doesn't do anything because it expects an animation name, and the animation name set in the sparticle editor doesn't seem to be available.

Flash Pro: Collision of objects only works correctly when on Frame 1

as you may have noticed just by reading the title it is quite hard to summarize the problem,
which is probably why I couldn't find a solution anywhere.
I am currently working on a flash game using adobe flash pro CC.
I started by creating the first level of my sidescrolling game and got everything to work just as I wanted it to. All my work was on a single frame (frame 1) and on a single layer and it worked fine.
However, when I then went on to move the frame a little further back and added frames in front of it for the menu I encountered a problem.
When I "gotoAndStop" to the frame with my game content on it, everything works except the collision between my character and my objects. My character is now sunk into the "floor object" about have his size, while when i move the frame back to "frame 1" everything works fine again.
I am losing my mind over this. Please help me :(
in flash when you start changing a dynamic property such as x or y, that object will be independent from the keyframe where it originally was ~forever~, even if you go back to the original keyframe. therefore if you start some enterframe and change the playhead afterwards you will get some awkward (but expected) behaviour.
ideally, jump to the game keyframe and just then call whatever methods needed to start the game.

HTML Canvas: How to address latency between user interaction and draw events?

I'm working on a game that allows players to click on a card and drag it across the screen in any random direction. There are a total of 64 100x80 overlapping cards on a 800x800 canvas at any one time and each one is a procedural draw. As some of you probably suspect, canvas doesn't like redrawing that entire canvas for every move. To work around this, I'm utilizing a buffer canvas to draw the card and then attempting to paint that buffer canvas to the main canvas using drawImage(). To ensure there is no drawing buildup, I clear the region of the canvas associated with where I plan to drawImage() using a clearRect().
The problem I'm experiencing is that because the (x,y) coordinates used for the clearRect() and drawImage() are coming from the location of the mouse, if the user moves too fast, the coordinates will differ from the time drawImage() was last executed to the time clearRect() is called during the next draw sequence. The result is residual draw from the last sequence - proportionate to how fast the card is being dragged.
I tried maintaining the (x,y) coordinates from the drawImage() and using those (instead of the current mouse location) for the clearRect() in the next sequence. However, now instead of residual draw being shown, residual we have residual clear (erase).
Thoughts on how I can address this?
NOTE: My animation rate is handled using RequestAnimationFrame and not SetInterval().
Assuming your canvas is static during the drag drop operation, a pretty easy way to get a good increase in performance would be to just cache the rendering.
In other words, when a drag drop operation begins, save the current canvas into another one. Stop all rendering except for the one involved with dragging the card. Now, whenever you need to repaint, simply repaint from your copy-canvas. Since you're basically just copying from one to another, it should be pretty fast.
On each processing cycle, you would take the current position of the dragged card, fill that with data from the copy, then redraw the dragged card in the new position.
Other approaches you could try would be to use some kind of a placeholder for the drag. For example, consider using a same-sized DIV which you display while dragging. This should have the benefit of not requiring to touch the canvas while dragging and thus also run a better performance for it.

Moving the "camera" of an HTML Canvas element

I'm trying to find a clean way to "move the camera" of a canvas element.
This for my prototype game (side scroller). I'd love to think there's a better solution than moving the whole set of nodes to simulate a "camera" moving around.
Am almost certain to have read a simple how-to (using offsets?) but the fact I don't find anything like that starts to raise doubts... have I imagined reading that!?
Thanks to help me clarify...
J
Presumably you redraw your whole game scene 30 times a second (more or less)
You need to redraw your whole game scene but first translate the Canvas context by some offset.
context.translate(x,y) is precisely what you want. You'll want to read up on the use of that as well as the save() and restore() methods.
When you translate the context, everything drawn afterwards is shifted by that amount.
So you constantly draw something (maybe an enemy) at 50,50 using drawImage(badguy,50,50). Then the player moves, which changes the x of translate to -1 (because the player is moving to the right) instead of 0. You still draw the enemy sprite with the command drawImage(badguy,50,50), but when you draw it the enemy shows up as if it were at 49,50 because of the context.translate(-1,0) command shifting everything before its drawn.
Of course when you get into performance you'll want to be making sure that you are only ever drawing things that can actually be seen on the screen! If your are far down the level with context.translate(-2000,0), you dont want to be drawing objects at 50,50 anymore, only ones that intersect the viewable area.