官术网_书友最值得收藏!

Character scene

Start creating the Character scene by adding an Area2D and naming it Character. Area2D is a good choice for this type of character because its main function will be to detect overlaps—when it moves onto an item or enemy, for example.

Add the following children:

  • Sprite
  • CollisionShape2D
  • Tween (named MoveTween)
  • AnimationPlayer

Leave the Sprite without a texture, but in the Inspector, under the Animation section of the Sprite, set its Vframes and Hframes properties to 4 and 5, respectively. This tells Godot to slice the texture into a 5 x 4 grid of inpidual images.

The spritesheets you'll use for the player and the enemy are arranged in exactly this pattern, with each row containing the animation frames for a single direction of movement:

When a spritesheet has been sliced using the Vframes and Hframes properties, you can use the Frame property to set which inpidual frame to use. In the preceding player sheet, the left-facing animation would use frames 5 through 9 (counting from frame 0 in the upper-left corner). You'll use an AnimationPlayer to change the Frame property below. Refer to the following screenshot:

Next, create a new RectangleShape2D in the collision shape's Shape. Click on the new <RectangleShape2D> and set its Extents property in the Inspector to (16, 16). Note that Extents measures the distance from the center in each direction, so this results in a collision shape that is 32 by 32 pixels.

Because all the characters are drawn to the same scale, we can be confident that the same sized collision shape will work for all characters. If this isn’t the case with the art you’re using, you can skip setting the collision shape here and configure it later for the inpidual inherited scenes.

主站蜘蛛池模板: 铜山县| 伊通| 永嘉县| 木兰县| 江津市| 大同县| 永州市| 定州市| 福海县| 上饶县| 四川省| 澎湖县| 仙游县| 尉氏县| 珠海市| 镇原县| 和田市| 靖边县| 景宁| 惠水县| 荔浦县| 双峰县| 蒙阴县| 扶沟县| 富川| 大关县| 华容县| 平度市| 岳西县| 安平县| 洛隆县| 米易县| 赞皇县| 四川省| 巴彦淖尔市| 达拉特旗| 白水县| 宁乡县| 泽州县| 博乐市| 内黄县|