Andengine ParticleSystem as Livewallpaper problems - andengine

First, I'll post link here where all is described by another person already
http://www.andengine.org/forums/gles2/particle-system-in-live-wallpaper-t8035.html
Well, the thing is, I set the ParticleSystem as a livewallpaper, and after the phone goes to sleep and I wake him up all particles are spawned at once. MaxRate and MinRate are ignored, max particles set in code is taken and the maxparticles possible are spawned.
But doesn't happens always, only sometimes. in 2 days it made this 3 times.
Any idea what could be wrong?
Question for ppl that know and engine.
Ty

Related

How to deal with Time.deltaTime to reproduce equal simulations in multiple machines

I'm doing a simulation online game where there are some balls that move over a table. The player a, in his turn, makes a move that creates a movement in some of the balls. I want player b to see exactly what a did.
I built the physics of the game from scratch, but I'm using Time.deltaTime in the calculations. I guess this is the problem. As the frame time differ from a's machine to b's machine, the simulation will take different values for Time.deltaTime from both machines every frame and won't be equally reproduced on them.
My question is: how can I overcome this problem? Should I just set a constant value to replace Time.deltaTime? Is there any built-in way to do that?
The main mission I want to accomplish is to have correctness between simulations, want the balls to have the exact same positions in both machines. The game time scale in both machines is important too, but not as fundamental as the results.

Unity3D forcing object to a given orientation with minimum artificial effect

In my board game, the points are given by throwing 7 sea-shells cowry shell. These shells are dropped onto a sphere in Unity so they get rolled over randomly to different places. Once the rigidbody.isSleeping() returns true, I do a Raycast(from the belly side downwards) to figure out the orientation of the shell. If it is NOT a hit we know the shells belly is turned upside which means a point.
All is good and very realistic when in single player mode. Reason is I just activate the gravity of the shells and they dropped on to sphere, gets rolled randomly and when stopped i get the marks as stated above.
Now the problem is I am making the game multiplayer. In this case, I sent the randomly generated marks from the server and client will have to animate the shells to represent the marks. For example, if server send 3, out of 7 shells, 3 should have it's belly turned upside.
Trying to do this has been a major problem for me. I tried to transform.Rotate() when the velocity is reduced but it was not very reliable and sometimes acts crazy. Rotating afterrigidbody.isSleeping() works but very unrealistic.
I know I am trying to defy physics here, but there may be some ways to achieve what I want with minimum artificial effect.
I actually need some ideas.
Update - 1
After infor I receive below, I did found some information here, some advanced stuff here. Since the latter link had some advanced stuff, I wanted to start small. So I followed the first link and did below test.
I recorded the position, rotation & velocity of the sea shell with autosimulation enabled and logged them to a file. Then i used the Physics.Simulate() for the same scenario and logged the same.
Comparing the two tells me that data in both cases are kind of similar. So seems like for my requirements I need to simulate the sea-shell drop and then apply that sequence to the actual object.
Now my problem is how can I apply the results of physics.simulate() results (position, rotation, velocity etc..) to the actual sea-shell so the animation can be seen. If I set the positions to my gameobject within the simulation loop nothing happens.
public void Simulate()
{
rbdy = GetComponent<Rigidbody>();
rbdy.AddForce(new Vector3(0f, 0f, 10f));
rbdy.useGravity = true;
rbdy.mass = 1f;
//Simulate where it will be in 5 seconds
int i = 0;
while (simulateTime >= Time.fixedDeltaTime)
{
simulateTime -= Time.fixedDeltaTime;
Debug.Log($"position: {rbdy.position.ToString()} rotation: {rbdy.rotation.ToString()} Velocity {rbdy.velocity.magnitude}");
gameObject.transform.position = rbdy.position;
Physics.Simulate(Time.fixedDeltaTime);
}
}
So, how can I get this simulated data applied to actual gameobject in the scene?
Assume Physics are deterministic, just set the velocity and position and let it simulate on each client. Output should be the same. If the output differs slighly, you could adjust it and it may be only barely noticable.
Physics.simulate may be interesting to read, even if it's kind of the opposite of what you want.
You can throw in the client, record the steps in realtime or using physics.simulate (see point 2) and transmit the animation data as binary - then use it in the other clients to play the animation.

Cloning Sprites in MIT-Scratch

Recently, in a project for school. I have come across an increasingly frustrating and what seems to be an unsolvable problem. Whilst attempting to create a diving game, in which the sprite of a diver (sprite x) touches clones of a fish sprite (referred to as y by me) to rack up scores as high as 25. While the mechanisms for diver movement appear to be completely fine. However, loading the game would result in no reaction from the fish and its clones. I had already programmed the clones of the fish sprites to hide and delete themselves if touching sprite x. However, the fish refused to clone itself even after many attempts at rewriting the script. I would like to know if there was anything I missed or screwed up. Thank you. And these are the images of the respective scripts of the sprites in links below. Thank you.
Here's your problem:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
CREATE CLONE OF "myself"
WAIT (6) SECS
BROADCAST "game over"
You're starting the game, waiting 2 seconds, cloning the fish 25 times, and then ending the game.
There's at least one issue here, and probably another.
First of all, you're cloning all of the sprites into the exact same spot. The clones are piling on top of each other, giving the appearance of only being one fish, since they're all in the exact same space. I'd advise moving to a random x and y on the stage in between each clone.
Second, you have BROADCAST "game over" immediately there. This works if this is the way you're implementing a time limit on the game, but otherwise, you're just ending the game 6 seconds after the last fish appears.
So, correcting these two things, you end up with something like this:
WHEN I RECEIVE "start game"
WAIT (2) SECS
REPEAT (25)
GO TO X: ([RANDOM PICK (-200) TO (200)]) Y: ([RANDOM PICK (-150) TO (150)])
CREATE CLONE OF "myself"
WAIT (6) SECS
If you want each fish to disappear after 6 seconds, then add a DELETE THIS CLONE to the above script.
You can delete this script:
That's now covered by the other script, above, and is also slightly buggy. It's kinda useless now.
And, in your other script, the one starting WHEN GREEN FLAG CLICKED... to have the fish disappear when touching the diver, replace the WHEN GREEN FLAG clicked with a WHEN I START AS A CLONE.

Restart SKEmitterNode without removing particles

I have a particle effect for a muzzle flare set up. What I'm currently using is a low numParticlesToEmit to limit the emitter to a short burst, and doing resetSimulation() on the emitter whenever I want to start a new burst of particles.
The problem I'm having is that resetSimulation() removes all particles onscreen, and I often need to create a new burst of particles before the previous particles disappear normally so they get erased early.
Is there a clean way start up the emitter again without erasing the particles already onscreen?
Normally particle systems have a feature missing from SKEmitters: a duration. This controls how long a system emits. I don't see this in SKEmitter, despite being in SCNParticleSystems
Never mind, a work around:
SKEmitters have a numParticlesToEmit property and a particleBirthRate. Combined, these determine how long the particle system emits before shutting down.
Using these as a control of the emission it's possible to create pulses of particles emitted in the way you want for something like a muzzle flash or explosion.
I'm not sure if it remvoes itself when it reaches this limit. If not, you'll have to create a removal function of some sort. Because the way to get your desired effect (multiple muzzle flashes on screen) is to copy() the SKEmitter. This is quite efficient, so don't worry about overhead.
There is a targetNode on SKEmitters that are suppose to move the particles to another node so that when you reset the emitter, the previous particles still stay. Unfortunately, this is still bugged from what I can tell, unless somebody else has figured out how to get it working and I just missed it. Keep this in mind though in case they do ever fix it.
Hi to help future readers, the code that I use to calculate the duration of the emitter is this:
let duration = Double(emitter.numParticlesToEmit) / Double(emitter.particleBirthRate) + Double(emitter.particleLifetime + emitter.particleLifetimeRange/2)
It works perfectly for me
Extension:
extension SKEmitterNode {
var emitterDuration: Double {
return Double(numParticlesToEmit) / Double(particleBirthRate) + Double(particleLifetime + particleLifetimeRange/2)
}
}

Help Required in Collision Detection Using Box2d

After some sample projects, I have started with my first game in cocos 2d and box 2d where objects fall from a parachute and you kill them using slingshot. Now i'm stuck # couple of things for a while:
Collision Issue:
Using Box 2d i have made collision with objects. However when i add a counter to get a count of my collision i doesn't work. Counter increases even though the percentile is moved out of the screen.Don't know how to get rid of this.
I'm trying to get random rotation to my sprites which fall from above, Like a parachute experience. Now all of then rotate # a same angle.
Lastly i need to get rid of the surrounding sprites when collision happens. Ex: When the percentile collides with a falling object, in a radius of 2.5 cms the other sprites should also disappear.
I Badly need help and suggestions, hence all the 3 questions # once :-). I have provided the link for my project so that you can look # the source code. Desperately looking for your help guys!!!
Download Source Code:
http://jumbofiles.com/6fn5mmpnq1q8/Karthik.zip.html
Budding Developer,
Karthik
You have a pretty good tutorial here: http://www.raywenderlich.com/475/how-to-create-a-simple-breakout-game-with-box2d-and-cocos2d-tutorial-part-12
I think that one can solve your problems :)
You can get the best tutorial for the particular requirement you have described over here.....
The link for that is as follows
http://www.raywenderlich.com/606/how-to-use-box2d-for-just-collision-detection-with-cocos2d-iphone
The tutorial is of 2 parts and describes the code briefly.. The code of that is described and you can get good amount of help from there.
ques 1 + 3: you need read link which share by Mikael and Marine
ques 2: in cocos2d, if you want get random value, you can use support function (such as: rand(), random(), CCRANDOM_0_1() ....)... i think, you need set rotation value for object. i dont know your problem, you need explain it (link is "File Not Found or Deleted / Disabled due to inactivity or DMCA")