Unity3D - Replay a non-looping Particle System - particle-system

I'm following the Survive Shooter Unity3D tutorial and have come across several inconsistencies between the Unite Day presentation and actual behavior in Unity 5.3, such as animation transition and other small issues I had to figure out to achieve the desired gameplay result and follow the tutorial.
One issue I'm unable to resolve is replaying a non-looping particle system. In the game hit particles are emitted whenever an enemy is shot, but when running the game these particles are emitted once and not upon following hits.
This is the particle system configuration:
The original code simply re-positions and re-plays the emission:
// Set the position of the particle system to where the hit was sustained.
hitParticles.transform.position = hitPoint;
// And play the particles.
hitParticles.Play();
I've tried resetting and clearing the system but that didn't work:
hitParticles.Clear();
hitParticles.time = 0;
hitParticles.Play();
How do I replay the particle emission?
thanks!

To reply the ParticleSystem try to use ParticleSystem.Emit(...) with parameters that suits your animation like:
hitParticles.Emit(5);

If you're using Unity 5.3.1, then it sounds very much like a bug(http://issuetracker.unity3d.com/issues/particle-system-plays-only-once).

If you need to reset immediately Particle system and repeat it (For example Rifle barel explosion) I would recommend you this:
ShootParticles.Simulate( 0.0f, true, true );
ShootParticles.Play();

Related

Is DragonBones compatible with libGDX?

I am trying to use DragonBone animations in my LibGDX game.
I am working on an endless runner game,so JSON levels will be loaded continuously and obstacles and coins get created each time level gets loaded.
Whenever I apply DragonBone animation for the obstacles,game is having a lag and white screen appears while executing code for collision.
Is DragonBone really compatible with LibGdx?
Or this problem occur because my code structure is not proper?(For each level,I am assigning DragonBone to each obstacles from a dragonBone array.Not able to use any loader for dragonBone also.Didn't get any code for that from net.)
Hope I will get some relevant suggestions.I am Really getting a hard time on this issue.

How do I create a simple on-mouse-click rotating object in flash

This question may get downvoted or go unanswered because it's not the greatest and incredible silly but anyway,
I'm taking an intro level Webanimation course this semester at UNI and had I know what their expectations are for our hand-in projects i would have never taken it up.
Basically the teacher taught us stuff to the extent of masking/tweening and very few mouse-event and basic function codes.
Now she is expecting us to make a god damn ENTIRE PIPE GAME. The one where there are a bunch of rotating pipes and you gotta rotate them in place before a timer runs out and then the water flows through them.
For this project I have to somehow figure out the following (even though she didn't teach any of this):
-creature a grid of rotate-able pipes (one mouse click I assume would do a 90 degree classic tween rotation of the object)
-creature some sort of logic hit-box value chain to make pipes decide when to fill with water (they fill with water (a.k.a turn blue inside as an animation) once they are connected to another water filled pipe, for example)
-creature multiple levels and a menu screen
-add a music track.
Now i know this site is for specific help only and you basically can't ask for help on an entire project, so for now if somebody could just help me out with the following:
How do I create a rotating pipe on mouseclick?
So I have my pipe movieclip created and I have my Mouse Event code ready but I don't have the faintest on how to make a tween within the pipe and connect it to the code so that it rotates on mouseclick.
So this far, let's say for one of the pipes, instance pipe_1, I want to do this:
pipe_1.addEventListener(MouseEvent.CLICK, fl_MouseClickHandler);
function fl_MouseClickHandler(event:MouseEvent):void
{
trace("Mouse clicked");
}
I also have the simple tween of rotation already created within the instance of the pipe, but dunno how to connect it to code.
I'm supposed to figure out what to put inside the function but I honestly have no clue. Hours of googling have come up with nothing either except a 12 dollar purchasable source code for an even more complicated pipe game.
I hope somebody can at least help a bit, and thanks.
The way to rotate a clip is via it's rotation property. It defaults to 0.
If you were set the rotation property of your tile to 90, you'd rotate your pipe tile 90 degrees.
for example :
pipe_1.rotation += 90;
A tween is a means of changing a property of a given DisplayObject over time. So what you want to do is tween your rotation property 90 degrees over time.
Here is a tutorial on Tweening - http://www.republicofcode.com/tutorials/flash/as3tweenclass/
I think it'd be more beneficial for you to take the time to learn about it, than to have me just write a few lines of code to solve your problem.
StackOverflow is a place where you can ask a question, AFTER you have tried something and have hit an issue.
I have provided you with the basic concept of what you need to do, and if you take the time to learn about tweening, you'll be able to achieve your goal rather simply.
There are also tweening libraries such as TweenLite and TweenMax that simplify tweening. Not sure if your class will allow you to use them, but worthwhile to check out for your own benefit.
You can find TweenLite here :
http://www.greensock.com/tweenlite/
Are you talking about a frame by frame tween? or tweening with code?
for frame by frame tweening, you can try to do this:
pipe_1.addEventListener(MouseEvent.CLICK, f1_MouseClickHandler);
function f1_MouseClickHandler(e:MouseEvent) {
pipe_1.gotoAndPlay(2); //if the tween starts at frame 2
}
For code tweening, just call the tween function inside that handler function

Animating from within classes in Actionscript 3 (Not on the timeline), what's the best way?

I've found some stuff online about how to animate in actionscript 3 from within a class, but haven't been able to find a really good tutorial. I want to control the animations from a class because at some point I intend to move from the flash IDE to using flash develop, where I won't have access to the Flash IDE's timeline.
I have to be able to control an initial animation (opening a bag) which joins onto an animation loop (searching through a bag).
The only way I have been able to do this so far is to add an event listener to listen for the initial animation's final frame. Then when initialAnimation.currentFrameLabel = "Last" then I gotoAndStop("animationLoop").
This has been working fine, if a bit time-consuming. I'm just wondering if there's a better, easier way to do it? Can anyone tell me or point me towards a tutorial that does it better? Thanks very much!
Romano
I recommend instead of using an event listener, you use the method addFrameScript. Essentially you can fire a method when a specific frame number is reached.
Read the following question for more information.
actionscript3 whats the point of addFrameScript
It depends on what it is you want to do:
Usually if you are working together with an artist or want to do animations that are non-code driven, the "best way" is usually to listen for something to happen, and then start animations and on last frame of animation (or when you want to return control to code) you create an event, or use a callback or something else to let code notify that animation is complete or reached a certain point.
If you want to do something from code, the easiest way is to use an external animation library.
Tweener (https://code.google.com/p/tweener/)
TweenLite (http://www.greensock.com/tweenlite/)
Using those libraries, you would write something similar to:
function fadeOut():void {
mc.alpha = 1;
Tweener.addTween(mc, {alpha:0, time:0.275, delay:1, onComplete:onDone});
}
function onDone():void {
trace("Animation finished");
}

libgdx: Is there a way to "fast-forward" particle effects?

I've worked with Game Maker previously to using libgdx, and one thing you could do is skip ahead in a particle's animation. For instance, if you have a snow particle effect, when you enter a room the snow particles would only just begin falling. But if you used the part_system_update() method repeatedly upon entering the room, you could "fast-forward" the effect, making it appear as if the snow had been falling before you entered the room. Is there a way to achieve that same result in libgdx?
Yes, you can update it when is created using the desired big float.
ParticleEffect#update
float startp = 0.5F; //for example
particleEffect.update(startp);

How to get rid of lag caused by lots of enemy instances?

im making a flash shooter game and ive encountered one problem. When there are a lot of monsters on the stage which are visible by player, the game starts to lag. In my opinion, its due to Event.ENTER_FRAME (each enemy instance has it) where z-sorting, enemy movement, updating other stuff like health is done. Since things like theese, cant be done each second or at similar time interval,im using ENTER_FRAME. My question is, how can i have many instances of the enemy in my game and still dont have it lagging. Ive done optimising in all over the code and if im not mistaken,big ammount of enemies is the performance bottleneck here.
Question me if i wasnt clear; to see the game go to http://ernyz.lhosting.info/bandymas.html or if you want to see the code,i will be able to put it here,just ask :)
Having an enter frame events for each instance is most likely the problem. A single event where you loop over all instances and do actions is usually faster.
There shouldn't be much for you to change: Instead of adding the listener to each enemy, add only one listener to the stage and call the enemies' update functions.
class Enemy {
function update(e:Event) { /* ... */ }
}
class Main {
function onEnterFrame(e:Event) {
for each (var enemy:Enemy in enemies) {
enemy.update(e);
}
}
}
From my experience, unless you're doing something very wrong, flash rendering pipeline is what takes the most time of your application. And since you get more enemies, you get more MovieClips and more complex rendering.
But having one ENTER_FRAME event for each object is indeed a big overhead that can be easily avoided.
A good practice before optimizing your code is to actually run it through a profiler. I don't believe the actual Flash program has it, but Flash Builder surely does. If you post us a screenshot or a log of the game being profiled, we can be of more assistance.
By quickly playing your game, I've seen that all your enemies are a bunch of graphics with a bunch of gradients, therefore costly to render. Have you tried setting the quality to low? Does the lag go away?