iadded stuff
This commit is contained in:
parent
19ca7b5aed
commit
f630727b16
6 changed files with 373 additions and 0 deletions
50
ch01/g10-tilemap terrains-part2.org
Normal file
50
ch01/g10-tilemap terrains-part2.org
Normal file
|
|
@ -0,0 +1,50 @@
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../../_share/media/css/org-mode.css" />
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />
|
||||||
|
#+title: godot 10 - Howto use Tilemap terrains (autotiles) in Godot 4, part2
|
||||||
|
|
||||||
|
[[../../arpg/toc.org][TOC - Godot Notes]]
|
||||||
|
|
||||||
|
* Application of autotiles
|
||||||
|
|
||||||
|
** Create Terrain set
|
||||||
|
|
||||||
|
1. select TileMapLayer node
|
||||||
|
2. Inspector-> TileMapLayer -> Terrain Sets (after Physics layers)
|
||||||
|
3. Add Elements initial
|
||||||
|
1. this creates a thing called "Terrains"
|
||||||
|
4. click 'add elements again'
|
||||||
|
1. rename terrain
|
||||||
|
2. pick color
|
||||||
|
|
||||||
|
** Choose terrains for terrain set
|
||||||
|
|
||||||
|
1. Go to TileMapLayer node
|
||||||
|
2. Click on Tileset at the bottom of the screen
|
||||||
|
3. click on "Paint" in "Setup, Select, Paint"
|
||||||
|
4. Select the "tiles" pane in the left side of bottom middle where it says "tiles/patterns"
|
||||||
|
5. select the correct tile map
|
||||||
|
6. Go to "Paint Properties" in middle bottom
|
||||||
|
7. select "Terrains", then which Terrain set under "painting"
|
||||||
|
8. select the corners/sides or corners and sides that apply to the terrain set
|
||||||
|
|
||||||
|
** alternative tilesset
|
||||||
|
|
||||||
|
*** create the tiles
|
||||||
|
|
||||||
|
1. Go to TileSet at bottom of screen
|
||||||
|
2. add a new terrain
|
||||||
|
3. click on "Select" in the middle bottom panel
|
||||||
|
4. right click on the tiles you like and select "create alternative tile"
|
||||||
|
5. scroll to upper right side of tileset viewer where you will see the "alternative tiles"
|
||||||
|
6. click to the right of the tiles to add more, duplicating the ones to the left
|
||||||
|
7. click on the options in 'rendering' in the middle pane to change the orientation of the selected tile
|
||||||
|
|
||||||
|
*** paint the tiles
|
||||||
|
|
||||||
|
1. switch to the paint tab in middle bottom pane
|
||||||
|
2. make sure the correct terrain set is selected
|
||||||
|
3. select the corners, sides or corners and sides
|
||||||
|
4. also make sure to paint the corners of the original tiles!
|
||||||
|
5. get the centers for the primary terrain
|
||||||
|
|
||||||
|
note: if you are using the darksand terrain pattern, make sure to also paint the corners of the original tiles
|
||||||
7
ch01/g11.org
Normal file
7
ch01/g11.org
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../../_share/media/css/org-mode.css" />
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />
|
||||||
|
#+title: godot 11 - Creating the First Enemey - AnimatedSprite2D
|
||||||
|
|
||||||
|
[[../../arpg/toc.org][TOC - Godot Notes]]
|
||||||
|
|
||||||
|
* Creating the first enemy
|
||||||
180
ch01/lesson-11.org
Normal file
180
ch01/lesson-11.org
Normal file
|
|
@ -0,0 +1,180 @@
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../../_share/media/css/org-mode.css" />
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../_share/media/css/godot.css" />
|
||||||
|
#+title: Lesson 11 - Creating the first enemy
|
||||||
|
|
||||||
|
[[../../arpg/toc.org][< Back to Main TOC]]
|
||||||
|
|
||||||
|
* Notes
|
||||||
|
** Create a New Sprite
|
||||||
|
*** add the nodes
|
||||||
|
1. Make a new scene
|
||||||
|
2. Add a CharacterBody2D node
|
||||||
|
3. to the new characterbody node, add a AnimatedSprite2D node
|
||||||
|
|
||||||
|
*** add animations node
|
||||||
|
1. add the sprite sheet to the project ./art
|
||||||
|
2. go to AnimatedSprite2D node-> Animated Sprite2D -> Animation-> Sprite Frames
|
||||||
|
a) click where it says empty, and select New Sprite Frames
|
||||||
|
b) now click inside "New sprite Frames", this will open up the SpriteFrames editor at the bottom
|
||||||
|
c) The options will be Animations and Animations Frames
|
||||||
|
|
||||||
|
*** add sprite sheet
|
||||||
|
1. click on 'default' in the animations section on the left side of the SpriteFrames editor
|
||||||
|
#+ATTR_HTML: :width 300px
|
||||||
|
[[../../_share/media/img/select animation.png]]
|
||||||
|
|
||||||
|
2. change name of the animation from 'default' to a name describing the animation
|
||||||
|
|
||||||
|
3. now click on the 'add frames from sprite sheet icon' in the Animations Frame panel of the
|
||||||
|
Sprite Frame Editor
|
||||||
|
#+ATTR_HTML: :width 500px
|
||||||
|
[[../../_share/media/img/add frames.png]]
|
||||||
|
- select the sprites you want to add and hit the Add button
|
||||||
|
- elements of the add frames
|
||||||
|
- horizontal and vertical determines rows and columns in spritesheet
|
||||||
|
- size determines pixel sizes
|
||||||
|
|
||||||
|
4. click on the 'new animation' button to add another animation and repeat the process above
|
||||||
|
#+ATTR_HTML: :width 300px
|
||||||
|
[[../../_share/media/img/add new animation.png]]
|
||||||
|
|
||||||
|
*** Reposition the Sprite
|
||||||
|
|
||||||
|
- this is important for y-sorting
|
||||||
|
|
||||||
|
- in the scene, select and move the sprite above the x-axis
|
||||||
|
|
||||||
|
see how the animation looks by going to AnimatedSprite2D-> Animation
|
||||||
|
choose from the dropdown in Animation to pick which animation you want
|
||||||
|
incrase or decrease the Frame number for the correct frame
|
||||||
|
|
||||||
|
*** add to world map
|
||||||
|
- save as whatever name you want
|
||||||
|
- switch to world scene
|
||||||
|
- add the sprite into the same layer area as the player
|
||||||
|
|
||||||
|
** make the sprite movable
|
||||||
|
- add a new script on the root node of the sprite
|
||||||
|
- erase everything in script except for extends CharacterBody2D at the top
|
||||||
|
|
||||||
|
*** =func _ready=
|
||||||
|
- Vector2(0, 3*16)
|
||||||
|
- 16 is the height of the sprite
|
||||||
|
- 3 is how many sprites spaces we move
|
||||||
|
|
||||||
|
- startPosition: where the sprite starts at
|
||||||
|
- endPosition: about 3 sprite lengths up
|
||||||
|
|
||||||
|
*** =func changeDirection=
|
||||||
|
- switch end and start positions
|
||||||
|
- this way it will regard as what was the end as the new start
|
||||||
|
|
||||||
|
*** =func updateVelocity=
|
||||||
|
- moveDirection: we compare where we have to go 'endPosition' to where we CURRENTLY ARE 'position'
|
||||||
|
- compare current position to goal position
|
||||||
|
- get difference
|
||||||
|
- use the normalization of the difference to find the direction =moveDirection.normalized=
|
||||||
|
- use the length of the difference to find if we hit the limit of how far we need to go =moveDirection.length < limit=
|
||||||
|
|
||||||
|
- =moveDirection.length < limit=: if so, change the direction as above
|
||||||
|
- =velocity = moveDirection.normalized * speed=:
|
||||||
|
- normalize the moveDirection so we get the direction alone
|
||||||
|
- multiple it by how far the sprite is expected to move at any given time
|
||||||
|
|
||||||
|
*** full script
|
||||||
|
|
||||||
|
#+begin_src gdscript
|
||||||
|
|
||||||
|
extends CharacterBody2D
|
||||||
|
|
||||||
|
@export var speed = 20
|
||||||
|
@export var limit = 0.5
|
||||||
|
|
||||||
|
var startPosition
|
||||||
|
var endPosition
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
startPosition = position
|
||||||
|
endPosition = startPosition + Vector2(0, 3*16)
|
||||||
|
|
||||||
|
func changeDirection():
|
||||||
|
var tempEnd = endPosition
|
||||||
|
endPosition = startPosition
|
||||||
|
startPosition = tempEnd
|
||||||
|
|
||||||
|
func updateVelocity():
|
||||||
|
var moveDirection = (endPosition - position)
|
||||||
|
|
||||||
|
if moveDirection.length() < limit:
|
||||||
|
changeDirection()
|
||||||
|
|
||||||
|
velocity = moveDirection.normalized() * speed
|
||||||
|
|
||||||
|
func _physics_process(delta: float) -> void:
|
||||||
|
updateVelocity()
|
||||||
|
move_and_slide()
|
||||||
|
#+end_src
|
||||||
|
|
||||||
|
** update the sprite-moving-script.gd
|
||||||
|
*** at beginning of script add: =@onready var animations = $AnimatedSprite2D=
|
||||||
|
1. =@onready=
|
||||||
|
- The =@onready= keyword tells Godot to initialize the variable after the node is added to the scene tree. Normally, if you try to access nodes in the scene tree during the script's initialization (before they're fully ready), you might get errors because those nodes don't exist yet.
|
||||||
|
- With =@onready=, the variable animations will be initialized once the node and its children have been added to the scene tree, ensuring it's ready to be used when the scene starts running.
|
||||||
|
2. =var animations=
|
||||||
|
- creates a variable named 'animations'
|
||||||
|
3. =$AnimatedSprite2D=
|
||||||
|
- The =$= symbol is a shortcut in Godot's GDScript to quickly reference child nodes in the scene tree. In this case, =$AnimatedSprite2D= accesses the AnimatedSprite2D node that is a child of the current node the script is attached to.
|
||||||
|
- =AnimatedSprite2D= refers to the specific node in your scene that handles sprite animations. It has functionalities such as starting, stopping, and switching animations.
|
||||||
|
*** func updateAnimation
|
||||||
|
- create a variable to hold the name of the animation you decide to play
|
||||||
|
- change this value based on the velocity of the sprite
|
||||||
|
- e.g. - if the velocity is greater than 0 set the animation to "walkDown"
|
||||||
|
- at the end of the function
|
||||||
|
- refer to whatever variable is set to your =$AnimatedSprite2D= objct
|
||||||
|
- call it's play function and pass the name of the animation you want to play
|
||||||
|
- e.g. =animations_node.play(animation_string_name)=
|
||||||
|
- make sure to call this function from the physics process!!!
|
||||||
|
|
||||||
|
|
||||||
|
** set end position to world scene marker
|
||||||
|
*** add marker 2D node to sprite
|
||||||
|
- go to world scene
|
||||||
|
- right click on sprite
|
||||||
|
- add a Marker2D node
|
||||||
|
- the marker pointer will be right on the sprite if you scroll in
|
||||||
|
- grab the marker crosshair and move it to where you want
|
||||||
|
*** add Marker2D to the sprite script
|
||||||
|
- =@export var endPoint: Marker2D=
|
||||||
|
- add an export variable
|
||||||
|
- specify the type is Marker2D
|
||||||
|
*** assign Marker2D to endpoint
|
||||||
|
- the Sprite inspector will now show an EndPoint property
|
||||||
|
- select the sprite
|
||||||
|
#+ATTR_HTML: :width 300px
|
||||||
|
[[../../_share/media/img/sprite-endpoint.jpg]]
|
||||||
|
- go to world, and drag the Marker2D object to the EndPoint property in the inspector for sprite
|
||||||
|
#+ATTR_HTML: :width 300px
|
||||||
|
[[../../_share/media/img/marker2d-world.jpg]]
|
||||||
|
- if you drag over the sprite object, then inspector will open up on that and you can move it over
|
||||||
|
|
||||||
|
*** in func _ready
|
||||||
|
- set endPosition to the global position of the endPoint marker
|
||||||
|
- global position is the actual position in the game
|
||||||
|
- regular position is relative to teh nodes parents' position
|
||||||
|
- =endPosition = endPoint.global_position=
|
||||||
|
|
||||||
|
|
||||||
|
* Video Contents
|
||||||
|
|
||||||
|
#+attr_html: :class content
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=VHsayee8NVDr4Ry9][00:00 Introduction]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=GG2BcV0rhJ4b8epF&t=19][00:19 enemy scene]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=9We59c3XSGKbWlEi&t=60][00:59 AnimatedSprite2D]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=C1mylGzZtosFZUwB&t=98][01:38 animations]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=OIq3oYJ5AWk41DsJ&t=194][03:15 add to world]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=CQexlsKAtUi8uFeQ&t=253][04:13 pixel snap]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=h97wsBEmojFO60rR&t=271][04:32 enemy movement]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=G5EvLXmC91RYUXaV&t=446][07:26 change direction]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=gPMPsk_CtNiMG485&t=506][08:27 update animation]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=EKWIowl3pqQ7UKY3&t=545][09:05 adding variation]]
|
||||||
|
- [[https://youtu.be/2oPzZqHR2Rg?si=-oNx4SQg639T0b0N&t=608][10:08 outro]]
|
||||||
78
notes 01.org
Normal file
78
notes 01.org
Normal file
|
|
@ -0,0 +1,78 @@
|
||||||
|
|
||||||
|
* Screen
|
||||||
|
|
||||||
|
** middle
|
||||||
|
- 2D view
|
||||||
|
- 3D view (default)
|
||||||
|
- Script
|
||||||
|
- AssetLib / Asset Library
|
||||||
|
|
||||||
|
** left
|
||||||
|
- inspector menu
|
||||||
|
- node menu
|
||||||
|
|
||||||
|
** right
|
||||||
|
- scene
|
||||||
|
- filesystem (below scene menu)
|
||||||
|
|
||||||
|
* how to start
|
||||||
|
|
||||||
|
** define root node of player
|
||||||
|
|
||||||
|
1. go to scene menu
|
||||||
|
2. click 'other node'
|
||||||
|
3. in create new node dialo,g select CharacterBody2D
|
||||||
|
- characterbody2d is what we use when we want to script
|
||||||
|
4. note the yellow warning triangle to the right of the node name
|
||||||
|
5. rename by clicking on the name and rename Player
|
||||||
|
6. save the scene
|
||||||
|
- will appear in filesystem dialog on lower left corner
|
||||||
|
|
||||||
|
** create a sprite node
|
||||||
|
1. select the player node
|
||||||
|
2. right click and select 'add child node'
|
||||||
|
3. in the dialog search for Sprite2D node
|
||||||
|
4. click on the Sprite2D node, look at inspector menu
|
||||||
|
|
||||||
|
** add art to project
|
||||||
|
1. go to filesystem
|
||||||
|
2. right click and add new folder 'art'
|
||||||
|
|
||||||
|
3. from a finder window, select whatever media files you want and add them to the art folder
|
||||||
|
|
||||||
|
** add art to the sprite
|
||||||
|
1. select the Sprite2D node
|
||||||
|
2. click and drag the media to the 'texture' property in the inspector menu
|
||||||
|
3. move the camera over to the center of the window
|
||||||
|
4. zoom in by clicking the + button at the upper left portion of the view screen
|
||||||
|
|
||||||
|
** fix pixel art
|
||||||
|
1. under 'canvasitem-texture-filter' in the inspector
|
||||||
|
2. select 'inherit' (unless the changes are only to this sprite)
|
||||||
|
3. go to player node
|
||||||
|
4. go to 'canvasitem-texture-filter'
|
||||||
|
5. change to 'nearest'
|
||||||
|
|
||||||
|
** change sprite into frames
|
||||||
|
1. go to sprite2D-animation
|
||||||
|
2. modify HFrames and Vframes so they have the correct number of rows and columns
|
||||||
|
3. you can change which frame you want to use, by going to the sprite2d-animation-frame and incrementing or changing the number to refer to which frame you want to use
|
||||||
|
|
||||||
|
** set size of viewport
|
||||||
|
1. go to project settings
|
||||||
|
2. scroll down to display settings
|
||||||
|
3. next select 'window' under display submenu
|
||||||
|
4. set viewport width and height
|
||||||
|
5. note that viewport doesn't mean window
|
||||||
|
|
||||||
|
** set stretch settings for game window so it doesn't affect items when the window is changed
|
||||||
|
1. project settings
|
||||||
|
2. go to display-window-stretch
|
||||||
|
3. set mode to 'canvas_items'
|
||||||
|
4. set aspect to 'keep'
|
||||||
|
|
||||||
|
** set window size
|
||||||
|
1. project settings
|
||||||
|
2. go to display-window
|
||||||
|
3. click 'advanced settings' in upper right corner of dialog box to the right of the search tool
|
||||||
|
4. go to 'window width override' and 'window heigh override' (1920, 1080)
|
||||||
|
|
@ -0,0 +1,47 @@
|
||||||
|
#+title: godot 10 - Howto use Tilemap terrains (autotiles) in Godot 4, part2
|
||||||
|
* [[../../arpg/toc.org][Table Of Contents]]
|
||||||
|
|
||||||
|
* Application of autotiles
|
||||||
|
|
||||||
|
** Create Terrain set
|
||||||
|
|
||||||
|
1. select TileMapLayer node
|
||||||
|
2. Inspector-> TileMapLayer -> Terrain Sets (after Physics layers)
|
||||||
|
3. Add Elements initial
|
||||||
|
1. this creates a thing called "Terrains"
|
||||||
|
4. click 'add elements again'
|
||||||
|
1. rename terrain
|
||||||
|
2. pick color
|
||||||
|
|
||||||
|
** Choose terrains for terrain set
|
||||||
|
|
||||||
|
1. Go to TileMapLayer node
|
||||||
|
2. Click on Tileset at the bottom of the screen
|
||||||
|
3. click on "Paint" in "Setup, Select, Paint"
|
||||||
|
4. Select the "tiles" pane in the left side of bottom middle where it says "tiles/patterns"
|
||||||
|
5. select the correct tile map
|
||||||
|
6. Go to "Paint Properties" in middle bottom
|
||||||
|
7. select "Terrains", then which Terrain set under "painting"
|
||||||
|
8. select the corners/sides or corners and sides that apply to the terrain set
|
||||||
|
|
||||||
|
** alternative tilesset
|
||||||
|
|
||||||
|
*** create the tiles
|
||||||
|
|
||||||
|
1. Go to TileSet at bottom of screen
|
||||||
|
2. add a new terrain
|
||||||
|
3. click on "Select" in the middle bottom panel
|
||||||
|
4. right click on the tiles you like and select "create alternative tile"
|
||||||
|
5. scroll to upper right side of tileset viewer where you will see the "alternative tiles"
|
||||||
|
6. click to the right of the tiles to add more, duplicating the ones to the left
|
||||||
|
7. click on the options in 'rendering' in the middle pane to change the orientation of the selected tile
|
||||||
|
|
||||||
|
*** paint the tiles
|
||||||
|
|
||||||
|
1. switch to the paint tab in middle bottom pane
|
||||||
|
2. make sure the correct terrain set is selected
|
||||||
|
3. select the corners, sides or corners and sides
|
||||||
|
4. also make sure to paint the corners of the original tiles!
|
||||||
|
5. get the centers for the primary terrain
|
||||||
|
|
||||||
|
note: if you are using the darksand terrain pattern, make sure to also paint the corners of the original tiles
|
||||||
11
toc.org
Normal file
11
toc.org
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
#+title: Godot Notes
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../../../_share/media/css/org-mode.css" />
|
||||||
|
#+HTML_HEAD: <link rel="stylesheet" type="text/css" href="../_share/media/css/godot.css" />
|
||||||
|
|
||||||
|
|
||||||
|
* Table of Contents
|
||||||
|
|
||||||
|
** Section 1 - Creating an RPG in Godot
|
||||||
|
|
||||||
|
*** [[file:./ch01/g10-tilemap terrains-part2.org][Lesson 10 - Tilemap Terrains (autotiles), part 2]]
|
||||||
|
*** [[file:ch01/lesson-11.org][Lesson 11 - Creating the First Enemy]]
|
||||||
Loading…
Add table
Reference in a new issue