6 Replies - 1510 Views - Last Post: 04 May 2011 - 06:08 PM Rate Topic: -----

#1 halfahack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 10-December 09

Animation and Scripting Relation in an RPG Engine

Posted 01 May 2011 - 06:35 PM

Ok, I have started yet another game engine fo making a 2D RPG. The problem is, in my last engine had no animation and I have no idea how to go about doing this. I have added a scripting language (of my own creation) which has a few commands that will ,hypothetically, make the player or any other NPC move (which will be animated) in the direction that is defined by one of the arguments in the command. I have no idea how to efficiently tell the target person object to walk in the direction that the command tells it to ,wait for the person to stop walking, and then efficiently continue the script where it left off. I'm thinking of adding a pause command that has one command and will pause execution of the script and assign the amount of milliseconds to a variable and start incrementing a counter variable (the loop is run every millisecond) and when the counter variable equals the target time variable, continue at the line in the script stored in another variable. Of course, I run into yet another problem. I have never dealt with animation before, and I have no idea how animation is conventionally dealt with ,as far as 2D tile-based games go. All of this kind of intimidates me ,and I may just drop animation completely ,but even if I do that I still want to know how to do it for future projects. Any help is appreciated.

Is This A Good Question/Topic? 0
  • +

Replies To: Animation and Scripting Relation in an RPG Engine

#2 sk1v3r  Icon User is offline

  • D.I.C Addict

Reputation: 231
  • View blog
  • Posts: 668
  • Joined: 06-December 10

Re: Animation and Scripting Relation in an RPG Engine

Posted 01 May 2011 - 06:42 PM

So you mean that you will have a command such as character.moveRight(100) or similar?
If so then what I would do would be to add it to a queue so that you can stack up moving in different directions, then when it comes to actually moving it see how far the earliest command wants the character to walk, and every frame move at a constant speed in that direction, and take the amount moved away from the value in the queue.

When the value in the queue is less than 0, remove it from the queue and carry on with the next value in the queue. This allows fluid movement over a number of frames.

I hope I haven't made it too mixed up too understand, but that is how I would do it :)
Was This Post Helpful? 0
  • +
  • -

#3 halfahack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 10-December 09

Re: Animation and Scripting Relation in an RPG Engine

Posted 01 May 2011 - 06:53 PM

Eh, it sounds like a great idea ,but still wouldn't know how to make the sprite animate. I'm not making this scripting language all that complex ,in fact, it is set up alot like ASM code ,where every line is occupied by only one line ,and the logical commands are similar to "cmp" and "jmp". As the "interpreter" (if you really want to call it that d: ) encounters each command it immediately executes it ,so having a queue would be against the original design.
Was This Post Helpful? 0
  • +
  • -

#4 RevTorA  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 251
  • Joined: 22-April 11

Re: Animation and Scripting Relation in an RPG Engine

Posted 02 May 2011 - 07:21 AM

The way I've done animation in the past is have each sprite that has animation (water, walking people, etc.) use a set amount of frames. Then have a counter that increments on each frame render (in your game loop), but loops back to 0 if it exceeds the maximum number of frames in a sprite's animation. Then you just choose the right frame for the sprite using that counter.

If you're talking about smooth movement, we need to know if you're using tile-tile movement, or free movement. Is it like Dragon Warrior, or Zelda:A Link to the Past?
Was This Post Helpful? 0
  • +
  • -

#5 RevTorA  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 251
  • Joined: 22-April 11

Re: Animation and Scripting Relation in an RPG Engine

Posted 02 May 2011 - 11:43 AM

Sorry for double post, but won't let me edit my last post X(

Concerning the scripting side of things, here's some pseudo code that might help you with the logic side of things:

Main Game Loop:
    For each script that's running
        Has this script's last command finished executing?
        If so, run the next command in script
        If not, go to next script
    
    Do other game loop stuff (input, updating, and drawing)


Was This Post Helpful? 0
  • +
  • -

#6 halfahack  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 10-December 09

Re: Animation and Scripting Relation in an RPG Engine

Posted 04 May 2011 - 04:15 PM

I am using tile by tile movements (I'm not sure how to go about free-movement yet ,seeing as I'm a beginning game programmer). Let's say you have a sprite on the map that is supposed to move in random directions every 5 seconds, how would someone program it to make the sprite smoothly animate from one tile to the other while switching between the frames?
Was This Post Helpful? 0
  • +
  • -

#7 RevTorA  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 76
  • View blog
  • Posts: 251
  • Joined: 22-April 11

Re: Animation and Scripting Relation in an RPG Engine

Posted 04 May 2011 - 06:08 PM

View Posthalfahack, on 04 May 2011 - 04:15 PM, said:

I am using tile by tile movements (I'm not sure how to go about free-movement yet ,seeing as I'm a beginning game programmer). Let's say you have a sprite on the map that is supposed to move in random directions every 5 seconds, how would someone program it to make the sprite smoothly animate from one tile to the other while switching between the frames?


Well, assuming you have some sort of wrapper around the sprite (like an NPC or Player), then I would have a variable indicating the state of the wrapper (I'll call it a character). Then, if the character is moving from one tile to another, the state would be "WALKING", and "STANDING" otherwise. You can then have a variable indicating a direction that the character is moving (NORTH, SOUTH, etc.), and finally a variable storing how far along the character is.

Pseudocode:
In the update function (called every 30th of a second or something similar)
    If State is WALKING
        Decrement pixelsRemaining

In frame drawing function
    If State is WALKING
        Use walking sprite for direction
        Target Tile's position = tile in the direction character is moving
        Character Sprite's "true" position = Target tile's position - pixelsRemaining
    Otherwise, just display as usual



Keep in mind how often you're calling your update function. I would suggest finding a way to fix it at a constant rate, say once every 30th of a second, or maybe 60th. You might need to only decrement pixelsRemaining once every X updates to slow down how quickly the sprite traverses from tile to tile.

It would help a lot however, if you were to post some code showing your current attempt. Then I, or anyone else willing, can help you get some working code :).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1