Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - Servious

Pages: [1]
1
releases / BlinkFX - for Flixel Power Tools
« on: Wed, Jul 31, 2013 »
Okay, so someone HAS to have made this before, but I can't find it, so I made one, and I'm posting it here.
Tell me if there's a better way to do this, but this seems to work great.

BlinkFX.as:
Code: [Select]
package org.flixel.plugin.photonstorm.FX
{
import mx.core.FlexSprite;
import org.flixel.FlxG;
import org.flixel.FlxSprite;
/**
* ...
* @author Servious
*/
public class BlinkFX extends BaseFX
{
private var _blinkInterval:Number;
private var _minAlpha:Number;
private var _maxAlpha:Number;
private var _fade:Boolean;
private var _fading:Boolean = true;
private var _counter:Number = 0;

public function BlinkFX()
{
}
/**
* A simple "blink" effect
* @param sprite The sprite you want blinking
* @param blinkInterval how long the whole blink cycle should take in seconds
* @param fade if it should fade while blinking, or just blink
* @param minAlpha the lowest alpha value possible
* @param maxAlpha the highest alpha value possible
*/
public function create(sprite:FlxSprite, blinkInterval:Number = 1, fade:Boolean = true, minAlpha:Number = 0, maxAlpha:Number = 1):void {
this._fade = fade;
this._maxAlpha = maxAlpha;
this._minAlpha = minAlpha;
this._blinkInterval = blinkInterval;
this.sprite = sprite;
if (_fade && this.sprite.alpha <= _minAlpha) {
_fading = false;
}
active = true;

}

public function draw():void {
if (ready) {
if (_fade) {

var factor:Number = ((_maxAlpha - _minAlpha) * 4) / (_blinkInterval / FlxG.elapsed);

if (_fading) {
sprite.alpha -= factor;
if (sprite.alpha <= _minAlpha) {
_fading = !_fading
}
} else {
sprite.alpha += factor;
if (sprite.alpha >= _maxAlpha) {
_fading = !_fading
}
}

} else {
_counter += FlxG.elapsed;
if (_counter >= _blinkInterval / 2) {
if (sprite.alpha <= _minAlpha) {
sprite.alpha = _maxAlpha;
} else {
sprite.alpha = _minAlpha;
}
_counter = 0;
}
}
}
}
}

}

and add this (and various imports) anywhere to FlxSpecialFX.as:

Code: [Select]
/**
 * Creates a blink Effect
 *
 * @return BlinkFX
 */
public static function blink():BlinkFX
{
var temp:BlinkFX = new BlinkFX

members[temp] = temp;

return members[temp];
}

BlinkFX.as has to go into org/flixel/plugin/photonstorm/FX

Here is an in-code example of usage:

Code: [Select]
FlxG.addPlugin(new FlxSpecialFX());
var pressEnter:FlxText = new FlxText(0, 0, FlxG.width, "PRESS ENTER");
var blink:BlinkFX = FlxSpecialFX.blink();
blink.create(_pressEnter, .25, true, .25);
blink.start();
add(blink.sprite);

That will create a FlxText that blinks from .25 alpha to 1 and back in .25 seconds!

Hope this helps someone!

2
help / Re: Flixel logo from particle emitter
« on: Tue, Jul 30, 2013 »
I bet you haven't set the amount of particles you need in the constructor of FlxEmitter.

I have tried that, but I'll try it again and see if it works.

Edit: Nope, that's not working either. Still flixel logos.

Okay, I figured it out. I had to set it to EXACTLY how many particles get emitted per FlxEmitter.emit()
I set it to something like 100 because I wanted to only have to use 1 emitter and just move it around to places where I wanted blood to be emitted. I guess I just have to make a bunch of FlxEmitters, one per instance of blood emission.

3
help / Flixel logo from particle emitter [SOLVED]
« on: Mon, Jul 29, 2013 »
Okay, I have no idea why this is happening-
  • I am using FlxParticle, and not FlxSprite
  • I've looked at everything on google, and nothing seems to work

Here's my setup function

Code: [Select]
private function setupBloodEmitter():void {
var particles:int = 10;
for (var i:int = 0; i < particles; i++) {
var particle:FlxParticle = new FlxParticle();
var size:int = Math.round((Math.random() * 3) + 1);
size = 1;
particle.makeGraphic(size, size, 0xffff0000);
particle.alpha = 1;
particle.exists = false;
_bloodEmitter.add(particle);
}
_bloodEmitter.maxRotation = 0;
_bloodEmitter.minRotation = 0;
}

and here's my emit function:

Code: [Select]
private function emitBloodPerticles(x:Number, y:Number):void {
_bloodEmitter.start(true, 1);
_bloodEmitter.x = x;
_bloodEmitter.y = y;
}

any help is appreciated! Thanks!

Pages: [1]