How can I move the character with keyboard?

Started by Tailgunner, Thu 01/04/2010 12:59:55

Previous topic - Next topic

Tailgunner

Hi everybody, i'm sorry for this stupid question but i really don't know how to use the new AGS!

So, my question is the same of the topic's subject  ;D :  I want move the character with the keyboard and i don't know how to do. There is a script or something like that? Because in the manual i didn't find anything, maybe i didn't search well.

And.. sorry for my really bad english, but i'm italian.  :D Thank you for the attenction!

Crimson Wizard

Create a game using Default template.
There's KeyboardMovement module in it. Check it.
(It already works in games made from Default template. but ofc you can copy it to other projects as well).

Tailgunner

Thank you very much! Now i'll check it!  ;)

Tailgunner

I've tried but it doesn't work.

I exported the scripts from the Defaul Template to the Verb Coin template and i could only move the mouse with keyboard, but not the character! There is something that i have to edit in the scripts?

Crimson Wizard

Hmm... they could be incompatible without some changes... let's see.

Ok, I got it.

In GlobalScript.asc find this inside on_key_press function:

Code: ags

  if (keycode==GetASCIINumber(LeftArrowKey)) mouse.SetPosition(mouse.x - 5, mouse.y);
  if (keycode==GetASCIINumber(RightArrowKey)) mouse.SetPosition(mouse.x + 5, mouse.y);
  if (keycode==GetASCIINumber(UpArrowKey)) mouse.SetPosition(mouse.x, mouse.y - 5);
  if (keycode==GetASCIINumber(DownArrowKey)) mouse.SetPosition(mouse.x, mouse.y + 5);


and either comment or delete it.

Tailgunner

I've tried to delete it but it doesn't work. Now i can't move the mouse with the keyboard and this it's ok, but i can't move the character too! They are both moved by mouse! I don't know if you understand, because my english is veeery bad and i'm sorry for it. :(

Matti

I'm not sure, but maybe the keyboard movement is disabled per default.

Put one of these lines into the gamestart section of the global script:

Code: ags

KeyboardMovement.SetMode(eKeyboardMovement_Tapping);
KeyboardMovement.SetMode(eKeyboardMovement_Pressing);


The pressing mode means that the character moves as long as an arrow key is pressed.
The tapping mode means that the character starts to walk once a key is pressed and stops walking as soon as the key is pressed again.

To disable the keyboard movement again call this:

Code: ags

KeyboardMovement.SetMode(eKeyboardMovement_None);

Crimson Wizard

Aah! Certainly. Mr. Matti is correct.

This is what is put in default template in game_start function:

Code: ags

KeyboardMovement.SetMode(eKeyboardMovement_Tapping); 


QuoteI don't know if you understand, because my english is veeery bad and i'm sorry for it.
I understand everything you say, don't worry  ;)

Danman

#8
I got this working. But exporting the KeyboardMovement_102 Module out of the Default game.  Then importing it in my own game.

Then putting this in the Game.start() function
Code: ags

KeyboardMovement.SetMode(eKeyboardMovement_Tapping); 

As Matti and Crimson Wizard explained.

It worked well for me
Hope this helps  ;D

Edit: Sorry Matti for misspelling your name . :P



Matti

Quote from: Danman on Thu 01/04/2010 15:15:26
As Matty and Crimson Wizard explained.

With an i please ;) It's pronounced Mu-tea by the way.

Danman




Tailgunner


SMF spam blocked by CleanTalk