Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation #25

Closed
coderoyalty opened this issue May 11, 2024 · 2 comments
Closed

Documentation #25

coderoyalty opened this issue May 11, 2024 · 2 comments
Labels
documentation Improvements or additions to documentation

Comments

@coderoyalty
Copy link
Owner

Script Reference

Hyper is still a work-in-progress engine at this time. The scripting system is in its alpha stage, and changes might happen without order; however, this guide remains viable for the scripting basics of the engine.

To attach a script to an entity, create a .lua

-- Player.lua
local Player = {}

return Player

The script must return a table. It is used to access other parts of the system. A script file has three primary methods.

-- called once, when the script was loaded
function Player:init()
end

-- called for every frame
function Player:update(dt)
end

-- called when the scene ends
function Player:destroy()
end

the init and destroy methods can be omitted, but the update method is required and compulsory; In other words, there should be no script file if there's no update method.

How to interact with the entity's component

Each script is attached to an entity, as a component. An entity can have many elements, and by default has an ID, tag and transform component. Presumably, these components are always existing for an entity.

Here's how we can interact with components from the script:

function Player:init()
  self.velocity = 10
  transform = self.owner:get(self.id(), Transform)
  print(transform.position)
  print(transform.scale)
  print(transform.rotation)
end

function Player:update(dt)
  transform = self.owner:get(self.id(), Transform)
  transform.position.x = transform.position.x + self.velocity * dt -- continue moving to the right
end

self.owner: The S in ECS. It's an interface to the scene's registry where entities and their components are managed. It provides methods such as has, get, valid, remove, clear and emplace. These methods take two parameters, an entity ID, and the component type.
self.id: The script's entity ID.

Available Components:

  • IDComponent
  • TagComponent
  • Transform
  • SpriteComponent
  • CircleComponent
  • TextComponent

reference /hyper/src/scene/components.hpp to see the component structures

@coderoyalty coderoyalty added the documentation Improvements or additions to documentation label May 11, 2024
@coderoyalty
Copy link
Owner Author

Editor Reference

alpha

Firstly, right-click the scene hierarchy panel and select the popup menu to create an entity. Select the new entity (already done by default), you should see its components rendered in the properties panel.

Nothing is rendered on the viewport for now, that's because the current entity does not have any drawable component yet. You should see a button labelled add component, click it and select your preferred drawable component (for the sake of this doc, choose SpriteComponent).

Congrats! You can play around with the entity, and also try using the controls (see below) to manipulate your entity"

Controls

Hot-Keys Uses Disabled Outside Edit Mode
Ctrl+O open scene True
Ctrl+N new scene True
Ctrl+S save a scene True
Ctrl + Shift + S save scene as True
G enable translation gizmo False
S enable scaling gizmo False
Q disable gizmo False
R enable rotation gizmo False
F5 play or stop a scene False

@coderoyalty coderoyalty pinned this issue May 12, 2024
@coderoyalty
Copy link
Owner Author

52c2f31 moving documentation to docs/ directory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

1 participant