Making a Sword Character

4

Stats

7,869 visits, 13,257 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 26 Dec, 2011. Last updated 19 Feb, 2019

Example Capx: Example

Obs: Adapted from my Little Knight game. Feel free to use the code as you wish, but please don't steal the assets :D

Step 1

Create all animations for your character. Walk, Jump... As you want. Then remove it's hands. Making it like this:

You'll separate the char's animations making two sprites: Character and Hands, each with the same animations and with the same names. The hands will have only one additional animation from Character: Attack. It's like this because the hands attack action must be detached from Character so that the Character can walk and attack, being idle and attack, jump and attack and so on.

Step 2

Add an image point called, ex.: SwordGrip for all hands animation frames.

Like so:

Name it the same for all frames.

And on the sword , just place the origin more or less on the handle point like this:

Add an image point on it as well, to mark where to put the collisor sprite. I'll explain about it soon.

Add as much as you want. Here i've added just one.

Step 3

The events :) . First add an attribute for character named ex.: 'Attacking' and another 'Direction'. And for the Sword: 'InitialAngle' and 'CurrentMovement'. Then add on Chararacter's events add:

Every Tick -> Hands: Set Position to Character

[SubEvent] Character: Not Attacking -> Hands: Set animation to

Character.AnimationName (from beginning)

Then for better organization add a group called ex. Movement

In it add an input event to make it change direction like:

Keyboard Left Pressed - > Character: Set Mirrored

----------------------------Character: Set 'Direction' to -1

----------------------------Hands: Set Mirrored

Keyboard Right Pressed - > Character: Set Not Mirrored

---------------------------Character: Set 'Direction to' 1

---------------------------Hands: Set Not Mirrored

This is just one way to do it. Make it however you want. Just set the hands mirrored when the character is and vice-versa.

Here too set your character animations depending on it's state. I'll not explain it here since it's out scope.

Now add a group ex. 'Attack'. On it add an input event to trigger the attack here i'll use mouse:

Mouse: On Left Clicked -> Character: Set Attacking to True

--------------------------Hands: Set Animation to Attack

--------------------------Hands: Set Animation speed to 50 (as wanted)

--------------------------Sword: Set 'InitialAngle' to Self.Angle

--------------------------Sword: Set 'CurrentMovement' to 1

Sword 'CurrentMovement' represents the movement type the sword will perform when the Chracter is attacking like a down slash, up slash, thrust etc. Here i'll use just one movement type. Change the 'CurrentMovement' as wanted an example is every click add one to 'CurrentMovement' so that on every click the sword moves differently.

Now add another event below this:

Character: Is 'Attacking'

Hands: On animation 'Attack' ended->Character: Set 'Attacking' to False

-----------------------------------Sword: Set Angle to 0

-----------------------------------Sword: Set 'CurrentMovement' to 0

Now, add another group to Character : 'WeaponPositioning'. On it add:

Every Tick - > Sword: Set Position to Hands (ImagePoint: 'SwordGrip')

[SubEvent] Character: Is Mirrored - > Sword: Set Mirrored

[SubEvent] Character: Is Not Mirrored - > Sword: Set not Mirrored

Step 4

Create dummy a dummy sprite to serve as collisor for the sword i'll call it 'SwordCollisor'.

On Sword events:

Every tick - > SwordCollisor: Set Position to Sword (imagepoint: 'CollisorPoint')

If you want more collisor's add more image points on Sword like CollisorPoint1 , CollisorPoint2 etc. And on 'SwordCollisor' add an attribute 'Point'. Then on top of Every Tick event add:

On Start of Layout: SwordCollisor: Set 'Point' to 1

--------------------Create SwordCollisor

--------------------SwordCollisor: Set 'Point' to 2

--------------------(repeat as needed).

Change [Every Thick] to this:

Every Thick

[SubEvent] Foreach SwordCollisor-> SwordCollisor: Set Position to

-----------------------------------Sword on ImagePoint

-----------------------------------'CollisorPoint' & SwordCollisor.Point

Handle the collisions between the SwordCollisors and the monsters as needed.

Now for the sword movements. In this example they are controlled based on the Hands current frame number.

Add a group: MovementStyles or SlashStyles. On it:

Sword: 'CurrentMovement' is 1 - >

[SubEvent] Hands: Animation Frame is 1 -> Sword: Set Angle to

------------------------------------------Self.InitialAngle -

------------------------------------------Character.Direction

------------------------------------------[*] 20 degrees.

[SubEvent] Hands: Animation Frame is 2 -> Sword: Set Angle to

------------------------------------------Self.InitialAngle -

------------------------------------------Character.Direction

------------------------------------------[*] 45 degrees.

[SubEvent] Hands: Animation Frame is 3 -> Sword: Set Angle to

--------------------------------------------Self.InitialAngle -

--------------------------------------------Character.Direction

--------------------------------------------[*] 5 degrees.

And so on. Change just the angle value, 20, 45, 5 as wanted.

You can change the animation speed as well for faster movement. Unfortunatelly right now you can't change the the current frame speed.

That's it. Be creative and change the sword angle and animation speed to crazy values and experiment.

  • 2 Comments

  • Order by
Want to leave a comment? Login or Register an account!
  • I'm not sure about this part (The events :) . First add an attribute for character named ex.: 'Attacking' and another 'Direction'. And for the Sword: 'InitialAngle' and 'CurrentMovement'. Then add on Chararacter's events add:)

  • Nice tutorial!

    I understand this is an older post, hoping for an updated link to the example .capx as construct.net/out is no longer valid.