Wintermute Engine Forum

Wintermute Engine => Technical forum => Topic started by: Mihulik on July 22, 2010, 08:14:14 AM

Title: Sprite moving and entity position
Post by: Mihulik on July 22, 2010, 08:14:14 AM
Hi,
I'd like to have an entity which is moving over a screen.
So, I made a sprite by SpriteEditor, added an image, set looping on true and set "Move by" on -3/0.
In SceneEditor I connected that sprite with an entity.

In a loop I check a position of that entity.
However, the entity X property is always 0.


I need to check whether the entity X property has some value and if so, I wanna change something.


I'd be glad of any help. :)

Thanks!
Title: Re: Sprite moving and entity position
Post by: metamorphium on July 22, 2010, 09:37:32 AM
please post your code
Title: Re: Sprite moving and entity position
Post by: Mihulik on July 22, 2010, 10:44:59 AM
Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. while(true){
  4. var fog = Scene.GetNode("fog");
  5.  
  6. if(fog.X <= -2142){
  7. fog.X = fog.X + 2142;
  8. }
  9.  
  10. Sleep(20);
  11. }

I attach the script when a scene is initializing:
Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. Game.AttachScript("scenes\Obzorye_Island-Beach\scr\Fog.script");
  4.  
  5. if(Game.PrevScene == "Obzorye_Island-Mountain_path"){
  6. actor.SkipTo(1423, 330);
  7. actor.Direction = DI_DOWN;
  8. actor.Active = true;
  9. }
  10.  
  11.  
  12. Scene.SkipTo(actor);
  13.  
  14. on "SceneShutdown"{
  15. Game.DetachScript("scenes\Obzorye_Island-Beach\scr\Fog.script");
  16. }


And detach it when the scene is shooting down:-)

The sprite is set in this way:
(http://img189.imageshack.us/img189/8679/spritej.jpg)
Title: Re: Sprite moving and entity position
Post by: Mihulik on July 24, 2010, 05:48:45 PM
Nobody knows?
I've been spending hours on trying to figure out what's wrong.

But I haven't found any problem yet:-/
Title: Re: Sprite moving and entity position
Post by: maze on July 25, 2010, 08:00:09 AM
Howdy Partner

I would use a different approach:
Attach your script in "Scene Edit" to the entity instead of loading it with AttachScript and change the code as following.

Code: WME Script
  1. #include "scripts\base.inc"
  2.  
  3. while(true){
  4.  
  5. if (this.X <= -2142) this.X = 2142;
  6. Sleep(20);
  7.  
  8. }

This will do the trick and is a lot easier
Title: Re: Sprite moving and entity position
Post by: Mihulik on July 25, 2010, 02:14:58 PM
Thanks!
I'll try it and let you know whether it'll help me :)
Title: Re: Sprite moving and entity position
Post by: Mihulik on July 25, 2010, 07:57:59 PM
It works well. Even more, your solution is much "cleaner" than my one.
I didn't know if I place an infinite loop into an entity script, it will work. I'm not so much experienced in WME. ;)

So, I thank you again for the working solution and mainly for the new finding. :)
Title: Re: Sprite moving and entity position
Post by: maze on July 27, 2010, 10:44:12 PM
No Prob.

This reminds me of the time when I was new to WME.