Please login or register.

Login with username, password and session length
Advanced search  

News:

IRC channel - server: waelisch.de  channel: #wme (read more)

Pages: 1 2 [All]

Author Topic: particles following mouse  (Read 10239 times)

0 Members and 1 Guest are viewing this topic.

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
particles following mouse
« on: July 12, 2008, 09:27:19 AM »

Hello again.
After a vacation in france, i cant wait to get back to Schach-Welten ...
so here i go with another question. I hope this wasnt asked before, but i didnt get any matching result searching the forum.

Is it possible to have particles following the mouse. Not in a special scene, but in the whole game ?
i know how to make particle effects and how to insert them in scenes ? i think this effect should be added in the game.script ?
How can i achieve this ?

Any help would be very welcome !

Greets
stucki

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: particles following mouse
« Reply #1 on: July 12, 2008, 12:32:06 PM »

I think the best way would be to use a transparent window containing one entity container. The entity would produce particles, and a script would periodically move the entity to the position of mouse pointer.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
Re: particles following mouse
« Reply #2 on: July 12, 2008, 04:46:08 PM »

thanks for the tip !
i have come so far ...

now i got the window named "mouse" with an entity container named "particles".

the window has a while(true) script that checks the mouse position and gives it to the window.

the entity container has the particle script with the method attached.

the window is loaded in the game.script.

i have given the window a text to test it and everythings works well. the text keeps the position of my mouse ...

how and where do i adress the entity container and do i call the method ?

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: particles following mouse
« Reply #3 on: July 13, 2008, 08:08:45 AM »

Do not move the window, only move the entity container. And the contained entity should start the particle emitter (just like your scene entities do now). And in CreateParticleEmitter() set the first parameter (FollowOwner) to true.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
Re: particles following mouse
« Reply #4 on: July 13, 2008, 08:52:18 AM »

okay i start to see ...

what i am not sure of is how and where to adress the entity .

now i have a window named "mouse" with an entity container named "particles" in which i have an entity named "emitter" which has my particle script assigned ( all done in the windows editor )

how do i adress the entity "emitter" from game.script to call the method declared in the particle script ?

var particlewindow = Game.LoadWindow("entities\mouse.window");
var test= particlewindow.GetControl ("emitter");
test.MakeSchachfelder ();

doesent work

09:55:
09:55: Runtime error. Script 'scripts\game.script', line 27
09:55:   Call to undefined method 'MakeSchachfelder'. Ignored.

what am i doing wrong ?

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: particles following mouse
« Reply #5 on: July 13, 2008, 09:11:56 AM »

GetControl() only gives you the container. Use the container's GetEntity() method to get the actual contained entity.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

Stucki

  • Frequent poster
  • ****
  • Karma: 0
  • Offline Offline
  • Posts: 325
  • I'm a llama!
    • View Profile
    • Schach-Welten
Re: particles following mouse
« Reply #6 on: July 13, 2008, 10:11:32 AM »

aaahh thats the point ! now i got it working !!
thanks very much for helping me out again !

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: particles following mouse
« Reply #7 on: December 22, 2008, 02:50:47 AM »

Did anyone else manage to do this? I don't really get to figure this and the particle stuff out... it would be a really nice addition to my project though. Can anyone make this as a small source code package to look at, experiment with and learn from?
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: particles following mouse
« Reply #8 on: December 22, 2008, 06:24:13 PM »

@Darky
Do you know how to make a particle effect and insert it in a scene?  I can help you with that if you don't. It's not really hard.  I used the demo.  F.e., to make snow, you make a folder called Particles in Data.  Copy the snowflake png and snowflake sprite from the demo.  Make a particle script file in the Particles folder and on it put:
#include "scripts\base.inc"


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
method MakeSnow()
{
  this.DeleteParticleEmitter();
  this.CreateParticleEmitter();
 
  var Emit = this.ParticleEmitter;
   
  Emit.AddSprite("particles\snowflake.sprite");
  Emit.X = 0;
  Emit.Y = 0;
  Emit.Width = Scene.Width;
 
  Emit.SetBorder(0, 0, Scene.Width, Scene.Height);
  Emit.SetBorderThickness(0, 0, 0, 100);
 
  Emit.LifeTime1 = -1;
  Emit.LifeTime2 = -1;
  Emit.LifeTimeZBased = true;
 
  Emit.Velocity1 = 20;
  Emit.Velocity2 = 50;
  Emit.VelocityZBased = true;
 
  Emit.Scale1 = 10;
  Emit.Scale2 = 100;
  Emit.ScaleZBased = true;
 
  Emit.Angle1 = 175;
  Emit.Angle2 = 185;
 
  Emit.MaxParticles = 300;
 
 
  Emit.GenerationInterval = 1000;
  Emit.GenerationAmount = 30;
     
  Emit.FadeOutTime = 1000;
 
  Emit.Start(20000);
}

Then in the scene where you want it to snow, put a scene entity and call it Emitter with a capital E.

In scene_init. script put:

var Ent = Scene.GetNode("Emitter");
Ent.MakeSnow();

And in scene add a script called Emitter.script and put on it
#include "scripts\base.inc"


////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
method MakeSnow()
{
  this.DeleteParticleEmitter();
  this.CreateParticleEmitter();
 
  var Emit = this.ParticleEmitter;
   
  Emit.AddSprite("particles\snowflake.sprite");
  Emit.X = 0;
  Emit.Y = 0;
  Emit.Width = Scene.Width;
 
  Emit.SetBorder(0, 0, Scene.Width, Scene.Height);
  Emit.SetBorderThickness(0, 0, 0, 100);
 
  Emit.LifeTime1 = -1;
  Emit.LifeTime2 = -1;
  Emit.LifeTimeZBased = true;
 
  Emit.Velocity1 = 20;
  Emit.Velocity2 = 50;
  Emit.VelocityZBased = true;
 
  Emit.Scale1 = 10;
  Emit.Scale2 = 100;
  Emit.ScaleZBased = true;
 
  Emit.Angle1 = 175;
  Emit.Angle2 = 185;
 
  Emit.MaxParticles = 300;
 
 
  Emit.GenerationInterval = 1000;
  Emit.GenerationAmount = 30;
     
  Emit.FadeOutTime = 1000;
 
  Emit.Start(20000);
}

I'm not sure if you need both the Particles script in the Particles file and the Emitter script in the scene but I have it that way and it works for me.

Now if you know that much, I haven't helped you very much but maybe it will help someone else.  :  )

You have to do the additional things mentioned in Mnemonic's posts to get the particles to follow the mouse but I haven't tried that yet.  The idea is somewhat similar except you're putting the Emitter in a window and then coding the particles to follow your mouse. 
« Last Edit: December 22, 2008, 06:34:18 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: particles following mouse
« Reply #9 on: December 23, 2008, 01:23:30 AM »

Thank you very much catacomber, now I have the particle system in my own project. You don't really need "emitter.script", but other than that it's exactly as you said. I spent a lot time to find out why the particle demo can use just this single file and I found out you just need particles.script in your particles folder. Then in your .scene with SceneEdit click to your Region Entity that has the Name "Emitter". In the properties window click Scripts... and then "Attach existing script" (the folder icon) and select the particles.script. You don't need emitter.script :)

I played around with the particles a bit, very nice.

But I have made no progress with the particles following the mouse here :( I'm trying around but it fails yet.

Hmm... I now have the smily entity but it doesnt emit my particle. And neither does it follow my mouse... here is what I have so far:
particles/particle.script from the demo. I added my particle based directly on the smoke particle. I will make bold whatever I think is important and might cause problems:

method CursorParticle()
{
  this.DeleteParticleEmitter();
  this.CreateParticleEmitter(true, MousePosition.X, MousePosition.Y);
 
  var Emit = this.ParticleEmitter;
   
  Emit.AddSprite("particles\cloud.tga");
  Emit.X = Scene.Width / 2;
  Emit.Y = Scene.Height / 2;
  Emit.Width = 0;
  Emit.Height = 0;
 
  Emit.LifeTime1 = 4000;
  Emit.LifeTime2 = 5000;
 
  Emit.Velocity1 = 50;
  Emit.Velocity2 = 70;
 
  Emit.Scale1 = 20;
  Emit.Scale2 = 90;

 
  Emit.Angle1 = 0;
  Emit.Angle2 = 20;
 
  Emit.MaxParticles = 300;

  Emit.Alpha1 = 255; 
  Emit.Alpha2 = 0;
  Emit.AlphaTimeBased = true;
 
  Emit.GenerationInterval = 0;
  Emit.GenerationAmount = 30;

  Emit.AddPointForce("wind", Emit.X - 100, Emit.Y - 100, 90, 10); 
     
  Emit.Start(30000);
}


I got entities/mouse.window with script particles/particles.script
Parentnotify - False
Transparent - True
Menu - False
InGame - True (?? I set this because I want my particle in front of inventory and so on)
PauseMusic - False

Layout
X - 0
Y - 0
Width - 1024
Height - 768



In it is an entity container called particles just as Stucki did.
Scripts - particles/particles.script
X - 70
Y - 50
Entity - entities\emitter_mouse.entity
Disabled - False
Visible - True


In the entity container now the entity emitter_mouse.entity:
ENTITY
{
  NAME="emitter_mouse"
  ACTIVE=TRUE
  X=MousePosition.X
  Y=MousePosition.Y

  SCALABLE=TRUE
  INTERACTIVE=TRUE
  COLORABLE=TRUE
  SPRITE="entities\emitter_mouse\sprites\default.sprite"
  TALK="entities\emitter_mouse\sprites\default.sprite"

  SCRIPT="entities\track_mouse.script"
  FONT = "fonts\outline_red.font"
}


My entities\track_mouse.script
// try to store position here
while(true)
{
   var MousePosition;
   
   MousePosition.X = Game.MouseX;
   MousePosition.Y = Game.MouseY;
   
   Sleep(1);
}


And in my scripts\game.script

// cursor particle
var particlewindow = Game.LoadWindow("entities\mouse.window");
var test = particlewindow.GetEntity("emitter_mouse");
test.CursorParticle();


Those are the errors I get:

02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Runtime error. Script 'scripts\game.script', line 6
02:47:03:    Call to undefined method 'GetEntity'. Ignored.
02:47:03:  Runtime error. Script 'scripts\game.script', line 7
02:47:03:    Call to undefined method 'CursorParticle'. Ignored.
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
02:47:03:  Compiling script 'particles\particles.script'...
02:47:03:    Error@line 220: Variable 'MousePosition' is referenced but not defined
« Last Edit: December 23, 2008, 02:54:04 AM by Darky »
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: particles following mouse
« Reply #10 on: December 23, 2008, 03:32:30 AM »

To understand how this works following the mouse, I'd have to try it.  I'll give it a shot but can't promise anything.  :  )

In particle script:

Changing
this.DeleteParticleEmitter();
this.CreateParticleEmitter(true, MousePosition.X, MousePosition.Y);

to

this.DeleteParticleEmitter();
this.CreateParticleEmitter(true, Game.MouseX, Game.MouseY);

gets rid of the MousePosition error

but I think you need higher help here  :  )  I'm yet a newbie.  :  )  I know you're asking for higher help, not mine.  :  )
« Last Edit: December 23, 2008, 04:30:11 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: particles following mouse
« Reply #11 on: December 23, 2008, 05:30:20 AM »

Darky,

Your while script to make the particle follow your mouse on the mouse.script attached to the mouse.window could look like this:

#include "scripts\base.inc"while(true)

   while(true)
{  this.X = Game.MouseX;
   this.Y = Game.MouseY;
   Sleep(1);
}

I put text in the Window "ho,ho,ho"

and it works!  :  )  : )

the words ho, ho, ho follow my mouse
this is so funny!!!!!  :  )  Useless but funny!

I don't have particles following yet but I am really delighted with this little effect--as a newbie, small things thrill me.  :  )

I'm not sure you need that smiley entity--the Emitter in the scene has no image attached to it.  It's just there.
« Last Edit: December 23, 2008, 05:44:45 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: particles following mouse
« Reply #12 on: December 23, 2008, 06:41:40 AM »

P.S.-I'm only trying this to help and out of curiosity--I think you would be a whole lot better off pming Stucki and asking him for help since he got this to work.

I would not use this as I think it's too distracting in my scenario from the gameplay.  You have to balance everything.  :  )  Whereas, in his and your scenario, it might work dramatically and add, not distract. 

I want the player to focus on what's going on in the game and not what the mouse pointer is doing.  :  ) That's just a stylistic difference.

IMHO, the mouse pointer should be inconspicuous unless there's a reason to  draw attention to it.

Again, that's just a style difference. 
« Last Edit: December 23, 2008, 07:06:21 AM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: particles following mouse
« Reply #13 on: December 23, 2008, 03:04:45 PM »

Wow thank you Catacomber, with your changes it now follows the mouse! Only problem is to cast the particles now but I am pretty sure that after a bit more trying around this can be found out as well. It should not be too hard since we got it in our scenes to work as well...


You are right it might be too distracting for some scenarios. But it can't hurt to have it in your resource box, can it? I've seen this thing in some games and with the right game setting and the proper particles and balancing it really can add a lot of atmosphere and experience to the player, since he uses the cursor most of the time. For me personally I have an more darker setting and I am really not sure how it would fit into my game. But I want to try and see how it looks and I could use it for eventual later games with another setting. Also I thought it's a good general thing to have here for anyone who want to or needs it :)

If we are unable more progress I will write to Stucki, in the meantime I try around some more I have the feeling it's just a tiny step missing to solve this completely.
« Last Edit: December 23, 2008, 04:03:42 PM by Darky »
Logged

Catacomber

  • Supporter
  • Frequent poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Female
  • Posts: 443
  • I love mice.
    • View Profile
    • Catacomber.com
Re: particles following mouse
« Reply #14 on: December 23, 2008, 05:07:35 PM »

It is probably something very simple.  Whenever I get this error "Call to undefined method 'WhateverMethodItIs'. Ignored", it generally means I'm not accessing the thing in the window I want to access.  And I will try to continue with this but from tomorrow night until Monday night I won't have much of a chance due to holidays.  :  ) 

The most impressive thing I've ever seen involving particles in a game are the smoke-filled dungeons in Castlevania Symphony of the Night. 
« Last Edit: December 23, 2008, 05:09:42 PM by Catacomber »
Logged
http://www.catacomber.com/
Code: WME Script
  1. Mnemonic is wonderful.
  2.  

Darky

  • Supporter
  • Regular poster
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 109
    • View Profile
    • Spreadcamp
Re: particles following mouse
« Reply #15 on: December 24, 2008, 10:51:23 PM »

I think you were right with the window access. I got it to work now.

I need to wrap it up now and reproduce it then I'll put a source project here

UPDATE:
Okay here is the source project: http://emotion-pixels.com/ftp/wme_particlecursor.rar

However I experienced performance problems (I am unsure if it's how I did it or if it's because of the particle I am using for my tests)
and of course it could need more tuning depending on what you would like to have for example a trail on your mouse.

Maybe we get this particle thing developed further, maybe not - but I think it's a nice start to have for anyone who wants this and to expand it.

Thanks to Catacomber for the very helpful assistance and trying around too :)
« Last Edit: December 24, 2008, 11:16:35 PM by Darky »
Logged
Pages: 1 2 [All]
 

Page created in 0.028 seconds with 24 queries.