Please login or register.

Login with username, password and session length
Advanced search  

News:

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

Author Topic: Sprite Animation  (Read 5105 times)

0 Members and 1 Guest are viewing this topic.

3D_Maniac

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 3
    • View Profile
Sprite Animation
« on: February 06, 2007, 09:08:32 AM »

I was wondering is it possible to have a 3D actor's direction linked to a sprites frame number.

In otherwords I have a Compass sprite and wanted it to display the direction the 3D actor was facing.
Logged

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Sprite Animation
« Reply #1 on: February 06, 2007, 09:24:53 AM »

Well, you can try something like this. Make a compass hand a sprite which will have its hotspot in the center. Also make it a square.
Then try some code similar to this (untested one).

Code: [Select]
var degrees = actor.DirectionAngle;  //returns in degrees the direction your 3d actor is facing

var tmp = Scene.GetNode("CompassHand");
tmp.Rotatable = true;

tmp.Rotate = degrees;

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Re: Sprite Animation
« Reply #2 on: February 06, 2007, 09:48:53 AM »

of course for this to work all the time, you'd have to create a script which you attach to your actor and where this will be in some
while loop.

Code: [Select]
#include "scripts\base.inc"

while (1)
{
   ... the provided code ...
   Sleep(10); //time how fast it should be updated without any Sleep your game will freeze
}

Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet

deviltry

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Sprite Animation
« Reply #3 on: July 03, 2008, 11:13:47 AM »

Hello.

Just startet working with Wintermute and also want to create something like a compass. I tried the code above and it works, but the rotation is very slow. It seems the game is updated only every second, although the Sleep function is set to suspend the script for only 20ms. Do you have an idea what's the reason or how to make the rotation work more fluently?
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Sprite Animation
« Reply #4 on: July 03, 2008, 11:39:20 AM »

Can you post your code? The game is definitely updated more often.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deviltry

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Sprite Animation
« Reply #5 on: July 03, 2008, 12:14:28 PM »

So far the code is as follows:

Code: [Select]
#include "scripts\base.inc"

global Line = Game.LoadEntity("entities\new_entity\new_entity.entity");

Line.Rotatable = true;

while(true){

  var mouseY;
  var alpha;
  var rad;
  var deg;

  mouseY = Game.MouseY-300;
  alpha = mouseY/200;
  rad = Math.Asin(alpha);
  deg = Math.RadToDeg(rad);
  Line.Rotate = deg;
 
  Sleep(20);
}

The "needle" shall only be influenced by the Y position of the cursor.
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Sprite Animation
« Reply #6 on: July 03, 2008, 01:06:23 PM »

If you add Game.Msg(deg); just before the sleep line, the game will be periodically displaying the calculated angle on screen. That way you can check what value your calculation returns.
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

deviltry

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Posts: 6
    • View Profile
Re: Sprite Animation
« Reply #7 on: July 03, 2008, 01:24:22 PM »

Thanks. The calculation is correct.
I've copied the code into a new script and removed the old one. Suddenly the rotation works fluently  ???  I think that's really strange *lol*  :)
Logged
 

Page created in 0.069 seconds with 19 queries.