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

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.

主站蜘蛛池模板: 通州市| 星座| 永顺县| 惠州市| 甘洛县| 观塘区| 米林县| 秭归县| 青川县| 洛扎县| 炎陵县| 瓮安县| 威海市| 静乐县| 富阳市| 博野县| 都昌县| 新源县| 五莲县| 获嘉县| 丰镇市| 鹿邑县| 富源县| 凤台县| 广平县| 东宁县| 罗甸县| 秀山| 呼伦贝尔市| 洛隆县| 当阳市| 鄂托克前旗| 合肥市| 澄江县| 陇西县| 南雄市| 庄浪县| 郑州市| 万州区| 望城县| 尼木县|