Simple Example of loading and using particle effect
Home › Forums › TimelineFX Module › Simple Example of loading and using particle effect
- This topic has 15 replies, 2 voices, and was last updated 15 years, 1 month ago by
redspark.
-
AuthorPosts
-
July 15, 2009 at 8:00 pm #3087
redsparkParticipantHi,
I was wondering if you could provide a short example of how to create and run a particle effect. I tried to copy the code from Vaders, modify it and use that. However, my framework separates the logic loop and the draw loop from each other. So I think I’m having trouble integrating the tweening mechanism. My particles don’t appear anywheres.
I’m calling particles.Update() in my logic loop at the number of frame ticks from the tween which is also updated in the logic loop. I call the particles.Drawparticles() passing the tween value in the draw loop. The two loops run at different speeds. Logic is called a lot more often than the drawing is.
I’d show you my code but the framework code is commercial and I can’t show my code without showing the framework code too.
I’m going to try again but it could also be that I’m running it on a mac and that is the problem. Is there anything I have to do to make it compatible with Mac or OpenGL? Thanks.
James
July 15, 2009 at 11:06 pm #3378
imported_peterigzParticipantOff the top of my head before I go to bed, are you using SetUpdateFrequency to set whatever the update frequency is? I wouldn’t have thought that would stop anything from being drawn though. In the doc folder of timelinefx mod is an example called tlParticleManager.bmx (rigz.mod/timelinefx.mod/doc) which is a very simple example. Try running that and see if it works. It can also be found here: http://www.rigzsoft.co.uk/index.php?option=com_content&view=article&id=24:a-simple-program&catid=5:module-help&Itemid=18 on this site in the help section.
Also just try compiling vaders and see if that runs ok on the mac. It should run ok, I can’t think of any reason why it shouldn’t.
July 16, 2009 at 12:34 am #3379
redsparkParticipantI didn’t call SetFrequency(). But I’m having a problem with the particles.update() for the particle manager now. It complains about a null object. I think I read somewhere in another thread about this. I’m going to take a look and see if I can update everything.
The Vaders wont run for the same reason. But the basic particle demo in the docs folder works fine. So I have to have something incorrect.
I also noticed in the tween module that the tween has a create method rather than a create function. I switched that around. I think I remember that being mentioned to do that too. May be I just have an old copy of the module and I need to update.
July 16, 2009 at 1:40 am #3380
redsparkParticipantI updated the modules and the extra module and used CopyEffect() instead of the tlEffect directly and it seems to work fine.
July 16, 2009 at 7:36 am #3381
imported_peterigzParticipantExcellent π so it’s working OK on the Mac then? That’s good to know.
July 16, 2009 at 10:22 am #3382
redsparkParticipantIt seems to be working but I’m getting some odd behavior. Perhaps I’m working in an unsupported mode too. First, I’m in 3D mode using MiniB3D within a Window. When I move my mouse outside of the window and my mouse graphic is not displayed because the cursor has moved outside of the window, I start getting a dark blue hue around every sprite that is displayed with an alpha channel. This doesn’t happen when I’m not displaying particles. It’s only when the particles are active and possibly when an effect is just loaded. But I haven’t tested that.
[attachment=1:o8f385sj]AlphaBlue.jpg[/attachment:o8f385sj]
Also, when this blue hue appears I notice a continuous bunch of sprites being drawn in the upper left corner which are not visible when the mouse is inside the window. It looks like my particle effect but I don’t know why it would be there. There is only one effect running and it is a copy of the template that I loaded. Could it be the template? When on pause it is more obvious that there is something going on in the upper corner. When the game goes on pause, it fades slightly. Whenever my games fades, I get this problem in the corner.
[attachment=0:o8f385sj]PausedProblem.jpg[/attachment:o8f385sj]
July 16, 2009 at 12:11 pm #3383
imported_peterigzParticipantThe blue hue sounds like it might be that some open gl states are not being reset since the particles were drawn. When you draw your sprites do you setcolor and setalpha before drawing them? ie.,
setcolor 255,255,255
setalpha 1
I’m not sure about the grey square in the top left as it doesn’t look like the same shape as the particles being drawn. Is it perhaps something else being drawn that you haven’t noticed before because the particles weren’t changing the open gl states at all ie., setrotation setscale etc.
Nice looking candle effect π
July 16, 2009 at 2:09 pm #3384
redsparkParticipantThe blue only shows up when the mouse is outside of the window and when I have the particles being displayed. I’ll try to set the colors and blend modes in each draw loop to see if that helps. It’s just strange why it does it only when the mouse is outside of the window.
To me, the gray squares look like the alpha channel of the particle being blended with the background. They rotate around a lot centred on that corner. They aren’t static. They seem to only do this when the screen is faded slightly. So I’m not sure what is causing it. I managed to code my way around the issue for fading the screen in and out but not for the slight dimming that the screen gets when it is on pause.
Perhaps both of these two problems are caused by the same thing. However, I have nothing drawing in the upper corner. If I shut off the particle system, the gray squares go away too. Doing a particles.clearall() removes it before I do a fade. And not drawing the particles until a fade is complete also prevents it. But I haven’t managed to find a way to pause the particles on the spot. Is there a way to do that?
I’m going to make the flame a little bigger and taller but I was pretty satisfied with it. I just need a tiny trail of smoke and I think it will be done. Thanks. π
July 16, 2009 at 2:54 pm #3385
imported_peterigzParticipantTo pause a particle manager call togglepause()
MyParticleManager.TogglePause()
And just call it again to unpause it.
Maybe you can post the code where you add the effect to the particle manager, it should be something along the lines of:
local candleflame:tleffect=copyeffect(myEffectsLibrary.GetEffect("Candle Effect")
'move it to where ever it should be on sreen
candleflame.setx(50)
candleflame.sety(400)
'Add it to the particle manager
MyParticleManager.AddEffect(candleflame)
Then it’s just a case of updating and rendering the particle manager in the main loop which it sounds like you’re doing OK.
July 16, 2009 at 3:53 pm #3386
redsparkParticipantMy field definitions look like:
' Particle Effects Fields
Field particles:tlParticleManager 'The main particle manager for GUI effects
Field effectslib:tlEffectsLibrary 'The effect library
Field CandleFlame:tlEffect
Field Tweener:tTweener
My loading method looks like:
' Setup Particles
SetUpdateFrequency(30)
Tweener = New tTweener.Create(30)
particles = CreateParticleManager()
particles.SetScreenSize(ScreenWidth, ScreenHeight)
particles.SetOrigin(ScreenWidth / 2, ScreenHeight / 2)
particles.SetIdleTimeLimit(5)
'load the effects library
effectslib = LoadEffects(Game.DataPrefix+"data/fx/Candle.eff")
CandleFlame = effectslib.GetEffect("Candle Flame")
Local e:tlEffect = CopyEffect(CandleFlame, particles)
e.sety(449)
e.setx(32)
particles.addeffect(e)
My Draw loop looks like:
' Draw Candles and effects
If Game.Fading()=0 Or Game.Paused=0 Then
Tweener.Update()
For Local Ticks:Int = 1 To Tweener.FrameTicks
Tweener.UpdateExecutionTime()
particles.Update()
Next
particles.DrawParticles(Tweener.Tween)
EndIf
July 16, 2009 at 4:32 pm #3387
redsparkParticipantI think I got it working. It was the SetScale, Color and Alphablending being carried over from the particle system interfering with the game graphics. It only worked when the mouse was on the screen because when the mouse was being displayed, it reset all of those things. π When the mouse wasn’t on the screen, they didn’t get reset because the mouse wasn’t drawn. Now the bluing is gone and so is the flicker in the corner.
Thanks for the help. I’m still new to Blitz and everything else. π
July 16, 2009 at 4:54 pm #3388
imported_peterigzParticipantCool, I’ll thought it might be something along those lines as it’s caught me out before too π
July 16, 2009 at 6:48 pm #3389
redsparkParticipantI’ll have to keep my eye out for that kind of thing in the future. π³
Is there a way to force the particle engine to start displaying the particles well into the simulation. For instance, I would like to load the scene with the candle already lit instead of waiting for the flame to actually be built. Could I just loop to update the particles for so many ticks to precalculate their positions?
Thanks.
July 16, 2009 at 8:06 pm #3390
imported_peterigzParticipantYeh, pre loading effects up to a certain number of frames is something I’ve had at the back of my mind a while.
Hmm, well I just gave it some thought tried a few things and now its implemented π ..so it will be in the next update which I should be able to upload tonight.
July 16, 2009 at 8:09 pm #3391
redsparkParticipantCool! I look forward to it. Thanks. π
-
AuthorPosts
You must be logged in to reply to this topic.