Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorhenrik
- CommentTimeFeb 3rd 2009 edited
Hi Guys
Im trying to visualize alot of data using the wonderfull flint system.
There althoug a couple of things I dont understand quite
I would like to make a distance calculation between all the elements and the mouse cursor
I dont know if there is a build in way of doing that ?
But what I have tried is to run through all the elements like this.
for(var i:uint; i<renderer.numChildren; i++){
trace(renderer.getChildAt(i).name)
var myelement = renderer.getChildAt(i);
trace(myelement.x) // traces the elements x pos
myelement.x = 5 // This goes not work
}
I can "read" the properties of the element but not set it ?
An other question is if there is a build in way to get a element to ease to a halt and a way to ease it up to speed again ?
What a generallt is trying to do is to have around a 1000 elements moving on the screen. When the mouse gets near one (or more) they should ease to a halt and also increase in size acoording to the distance. This is because the user needs to be able to clikc each element which is har when they are really small and they are speeding about.
If any one could give me a few pointers on how to achive this it would be very thankfull
Best Regards
/Henrik
Best Regards
/Henrik -
- CommentAuthorRichard
- CommentTimeFeb 3rd 2009
Hi Henrik
If you try moving the sprites directly, as you are doing, the system will immediately move them back to where they should be. You have to change the position of the particle and the sprite will follow. The particles are all in the emitter's particle array. They are usually modified by using an action - an action operates on all particles in the emitter. Your basic test, as an action, would look like this...package
{
import org.flintparticles.common.actions.ActionBase;
import org.flintparticles.common.emitters.Emitter;
import org.flintparticles.common.particles.Particle;
import org.flintparticles.twoD.particles.Particle2D;
public class TestAction extends ActionBase
{
override public function update( emitter:Emitter, particle:Particle, time:Number ):void
{
var p:Particle2D = particle as Particle2D;
p.x = 5;
}
}
}
Add the action to the emitter withemitter.addAction( new TestAction () );
Obviously, you need a more complex action for your project. Any actions should extend the ActionBase class or implement the Action interface. You'll probably want custom initializers too - these extend the InitializerBase class or implement the Initializer interface. Flint will take care of the rest. -
- CommentAuthorhenrik
- CommentTimeFeb 3rd 2009
ok great, sounds good.
If I may I have a follow up question. (or 2 ) :-)
using the update override. How should I aproach looping through all the particles to be able get thier coordinates og set the position ?
And how will I allow flint to regain control of the particle when I done controlling it with my custom script. ?
Basically it need to some thing like this ( in bable code ) :-)
loop all the particles
control some of the particels with at custom script
when im done controlling them, "release" them to be controlled by flint again.
I think I can code alle the behavios if it was just some normal sprites moving around by my own code. Just need to now how to do the same with flint as my friend :-)
Thanx in advance
/Henrik -
- CommentAuthorRichard
- CommentTimeFeb 4th 2009 edited
The update method is called every frame and for every particle (that is the particle parameter). Any code you place in here will be used to affect every particle. If you want to base the action on the distance from the mouse, you'll have something likeif( particle.x - renderer.mouseX < 50 && particle.y - renderer.mouseY < 50 )...
Your custom action is not removing control from Flint - each emitter uses a combination of all the actions assigned to it to control the particles. You are simply choosing to pass your own action as one of those controls.
Take a look at some of the actions in Flint for hints. Mouse related ones like TurnTowardsMouse could be very helpful. -
- CommentAuthorhenrik
- CommentTimeFeb 4th 2009
ahhhhh...now I understand much better.
I am now trying to give each particle a special color acording to which kind of data it represents.
I would like to set this color already when they are beeing created by the emitter. Do you know how to do that ?
I would also like to give each particle a id of some sort so that when the user clicks on it I will be able to "lookup" the details in an array.
so basically:
I have a array if data that needs to be represented by particles
so again in bable code, im thinking:
loop the array
create particle, with color and size according to type
parse the currentIndex of the array to the particle to remember.
then..
user clicks on particle
get the index from clicked particle
look detalied data in the array
---
Any thoughts or pointers ?
Thanx in advance
/H -
- CommentAuthorRichard
- CommentTimeFeb 9th 2009
For colour, look at the color initializers like ColorInit for hints. For the id, each particle contains a Dictionary - its dictionary property - for storing custom data in. If you want to avoid the counter and initializers and instead use custom code to create the particles, create the particles in your code then use the addExistingParticles method to add the particles to the emitter.
1 to 6 of 6
