How to set the position of an effect?
Home › Forums › TimelineFX Module › How to set the position of an effect?
- This topic has 16 replies, 2 voices, and was last updated 14 years, 1 month ago by imported_peterigz.
-
AuthorPosts
-
October 13, 2010 at 9:11 pm #3194
The CzarParticipantI feel really stupid but for the life of me I cannot figure out how to set the position of effects on the screen. I have tried all kinds of set this and that methods but after the initial placement, it remains fixed on the screen. I’m trying to integrate it into an existing game engine, so I need to control these things manually. How can I do something like this?
Local effect:tlEffect
While Playing
effect.SetPosition(x, y) ‘different every frame
effect.Draw()
Flip
WendOctober 14, 2010 at 4:45 pm #3770
imported_peterigzParticipantHello, your example is basically how you would do it.
Taking the sample code from this site, to move the effect around with the mouse you could do:
SuperStrict
Import rigz.timelinefx
Import rigz.tweener
'Load the effects library
Local MyEffectsLib:tlEffectsLibrary = LoadEffects("effects/examples.eff")
'Create an effect and assign it an effect from the library
Local MyEffect:tlEffect = MyEffectsLib.GetEffect("simple explosion 1")
'Create the particle manager to manage the particles
Local MyParticleManager:tlParticleManager = CreateParticleManager()
Graphics (1024, 768, 0)
'These commands are important to set the origin of the particle manager. For this example we're setting the origin so that
'effects will be placed at screen coordinates. If you leave out the setorigin command then an effect created at 0,0 would
'be placed at the center of the screen.
myparticlemanager.SetScreenSize(GraphicsWidth(), GraphicsHeight())
myparticlemanager.SetOrigin(GraphicsWidth() / 2, GraphicsHeight() / 2)
'This will make one frame equal 33 millisecs long - or 30 updates per second.
SetUpdateFrequency(30)
'Create a tweener using the tweener mod. Make sure its frequency matches that above
Local Tweener:tTweener = New tTweener.Create(30)
local mouseeffect:tleffect
'Our main loop
While Not KeyDown(KEY_ESCAPE) Or AppTerminate()
Cls
If MouseHit(1)
'to create an effect you need to use the copyeffect command, and copy the MyEffect you created earlier.
'You shouldn't use MyEffect as it is the template
'for which is used to create effects you draw on screen.
Local tempeffect:tlEffect = CopyEffect(myeffect, MyParticleManager)
'Set the temp effect to the mouse coords
tempeffect.setposition(mousex(),mousey())
mouseeffect=tempeffect
'add the effect the the particle manager. Important, otherwise the particle manager would have nothing to update
MyParticleManager.addeffect(tempeffect)
End If
'here is the timing code, update the tweener to get the number of ticks for this loop
Tweener.Update()
For Local Ticks:Int = 1 To Tweener.FrameTicks
'Update the execution time for the tweener
Tweener.UpdateExecutionTime()
'Update the particle manager
if mouseeffect mouseeffect.setposition(mousex(),mousey())
MyParticleManager.Update()
Next
'and finally draw the particles.
MyParticleManager.DrawParticles(Tweener.Tween)
Flip 0
Wend
That’s just a very rough example, but is basically what you’d have to do. You can also download the vaders source code from the downloads page for some more insights, for example the bullets are effects that are moved about the screen.
October 14, 2010 at 10:15 pm #3771
The CzarParticipantI’ve tried all that and it doesn’t work š„
Here is the code that sets the position:
If _effect Then _debugtext = "effect"
?Debug
If _debugtext.Length > 0
DrawText _debugtext, pos.x, pos.y
End If
?
If _effect
_effect.SetPosition(pos.x, pos.y)
End IfThe debug text appears at the correct position on the screen, but the effect never moves from its starting point. I’ve got all the particle managers and tweeners and stuff doing their thing. What’s wrong???
October 14, 2010 at 10:38 pm #3772
imported_peterigzParticipantCan you attach the specific effect you’re trying to move about? I think the only thing I can think that might be causing a problem is if you are using an effect that has a single particle but it’s not as relative so therefore it wouldn’t move about with the effect.
If you can send the effect though I could do a little example with it.
October 16, 2010 at 6:11 pm #3773
The CzarParticipantI think I’m a bit closer to the problem. When I tell an explosion to change position, it can leave trials of effects as it moves. But I’m using SetPosition to move it accross the screen as I scroll around the map – the explosion isn’t physically changing position. What’s the best way to change the position of an effect on the screen without the effect thinking it is moving?
October 16, 2010 at 6:25 pm #3774
The CzarParticipant[attachment=0:33yzb981]Screen2181.jpg[/attachment:33yzb981]
This screenshot shows what I mean. I scrolled to the side and it made the water flow like that, when it should still go up in a straight line.
October 16, 2010 at 7:28 pm #3775
imported_peterigzParticipantAhh I see. Then I think you need to look at the ParticleManager.SetOrigin(x,y) command. You can change the origin of particle managers specifically so that you can move effects about with your camera.
So just set the origin of the particle manager to match your camera coordinates and all particles drawing will be offset by this.
October 17, 2010 at 8:55 pm #3776
The CzarParticipantOk I’ve got it working now, thanks!
Another question: I have an engine trail effect from a rocket. As the effect is attached to the rocket, when the rocket hits its effect is deleted and the effect stops suddenly, which looks bad. So I’ve made a list of dying effects and when an object dies, it puts its effects into that list. I want effects in that list to fizzle out and then remove when they are finished. How could I go about doing this? How do I tell an effect to die, and check when it is dead?
October 17, 2010 at 11:03 pm #3777
imported_peterigzParticipantYou can use effect.SoftKill() which tells it to stop spawning particles allowing any existing particles belong to the effect to just dying out.
October 23, 2010 at 9:45 pm #3780
The CzarParticipantOK thanks that’s working now.
Is there a way to flip between compiled mode? I would like to turn off compiled mode sometimes to load quicker for a test. Does it have a significant impact on loading speeds?
October 24, 2010 at 2:39 pm #3783
imported_peterigzParticipantTo switch a particle manager to use interpolated mode you can call MyParticleManager.SetUpdateMode(tlUPDATE_MODE_INTERPOLATED) and do MyParticleManager.SetUpdateMode(tlUPDATE_MODE_COMILED) to set it back. And when you load in effects set the compile parameter to false so that it doesn’t compile. I noticed though that there’s a bit of code to do with how it loads in the shapes that can be optimised quite a bit, so I might try and sort that out. It’s mainly only loading in shapes with a lot of frames of animation that is the main reason it can be slow sometimes.
October 25, 2010 at 10:01 pm #3787
The CzarParticipantThank you, you are really very helpful. When I sell my game I will definately make a donation for you. š
Another question. I want to create a tesla coil weapon like in Red Alert games. Can I do this with Timeline FX? It means I will need two points, the orb of the coil and the target. Can that work? Thank you.
October 25, 2010 at 10:06 pm #3788
The CzarParticipantWith this code
Function Load()
particle_manager.SetScreenSize(TSettings.resolution_x, TSettings.resolution_y)
particle_manager.SetOrigin(TSettings.resolution_x/2, TSettings.resolution_y/2)
particle_manager.SetUpdateMode(tlUPDATE_MODE_INTERPOLATED)
For Local dir:String = EachIn LoadDir("DataEffects")
If Not _effects.Contains(dir) Then _effects.Insert(dir, LoadEffects("DataEffects" + dir, False))
Next
SetUpdateFrequency(15.0)
Tweener = New tTweener.Create(15)
End FunctionI get a Null object error here
'
Speed
If Not bypass_speed
e.speed = c_velocity.changes[0]
e.velvariation = Rnd(-current_speedvariation, current_speedvariation)
e.basespeed = (current_speed + e.velvariation) * parentEffect.currentvelocity
e.velseed = Rnd(0, 1.0)
e.speed = c_velocity.changes[0] * e.basespeed * c_globalvelocity.changes[0]October 26, 2010 at 7:39 am #3791
imported_peterigzParticipantIt’s been a while since I tested interpolated mode so I will fix that tonight, thanks for the example!
October 26, 2010 at 9:32 pm #3793
imported_peterigzParticipantI’ve fixed this and updated the SVN if you can grab it from there. Seemed to be working ok in the tests I made.
-
AuthorPosts
You must be logged in to reply to this topic.