core/touchraycaster
터치 레이캐스터.
Touch raycaster.
TouchRaycasterextends Object
터치 레이캐스터.
- 씬의 터치(Scene.tickTouch 가 씬의 레이캐스터에 넘긴다, Scene.setTouchRaycaster)를 받아 루트 노드 트리를 draw() 순서로 순회하고, 활성 + isInteractable() 노드 중 가장 앞(높은 번호)의 노드에 터치 이벤트를 전달한다.
- 노드 종류는 가리지 않는다. isInteractable 과 contains 가 있는 노드는 WorldNode 가 아니어도(UINode 등) 맞을 수 있다.
Touch raycaster.
- Receives the scene's touches (Scene.tickTouch passes them to the scene's raycaster, Scene.setTouchRaycaster), traverses the root node tree in draw() order, and among active + isInteractable() nodes, delivers the touch event to the frontmost (highest number) node.
- Node types are not restricted. A node with isInteractable and contains can be hit even if it is not a WorldNode (UINode, etc.).
import { Engine, EngineConfiguration, Scene, TouchRaycaster, WorldNode, Vector2 } from "./build/vanilla.js";
class ButtonNode extends WorldNode {
touchPress(viewInputPosition) {
console.log("pressed", viewInputPosition.x, viewInputPosition.y);
}
}
class MainScene extends Scene {
initialize(engine) {
const root = this.getRoot();
const buttonNode = new ButtonNode();
root.addChild(buttonNode);
buttonNode.setRect(100, 100, 200, 80);
buttonNode.setInteractable(true);
const touchRaycaster = this.getTouchRaycaster();
touchRaycaster.setFirstTouchCallback(() => {
console.log("first touch");
});
const hitNode = touchRaycaster.raycast(Vector2.create(150, 120));
console.log(hitNode === buttonNode, touchRaycaster instanceof TouchRaycaster);
}
}
const engineConfiguration = new EngineConfiguration();
const engine = new Engine(engineConfiguration);
engine.run(new MainScene());생성.
Constructor.
터치 누름.
- raycast로 대상을 결정하고 touchPress를 전달한다.
Touch press.
- Determines the target with raycast and delivers touchPress.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
터치 이동.
- press 시 결정된 대상에 touchMove를 전달한다.
Touch move.
- Delivers touchMove to the target determined at press.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
터치 뗌.
- press 시 결정된 대상에 touchRelease를 전달하고 대상을 해제한다.
Touch release.
- Delivers touchRelease to the target determined at press and releases the target.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
터치 취소.
- press 시 결정된 대상에 touchCancel을 전달하고 대상을 해제한다.
Touch cancel.
- Delivers touchCancel to the target determined at press and releases the target.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
마우스 휠. (touchPress 와 무관하게 매번 viewInputPosition 으로 휠을 받을 스크롤 칸을 찾아 wheel 을 전달.)
- 그 자리를 덮는 것 가운데 그리는 순서로 가장 앞이 스크롤 칸(노드가 그 자리를 품은)이면 그 칸이 받는다. 그 칸 안의 글이나 그림처럼 누를 수 없는 것 위에서 굴려도 칸이 받는다.
- 가장 앞이 누를 수 있는 노드면 그 노드와 부모 체인에서 첫 스크롤 칸이 받는다. (스크롤 칸을 덮은 막이나 창이 휠을 가린다)
- 받은 칸이 있으면 true.
Mouse wheel. (Regardless of touchPress, each time finds the scroll view that receives the wheel at viewInputPosition and delivers wheel.)
- If the frontmost in draw order among the things covering that point is a scroll view (whose node contains that point), that view receives it. It receives it even when the wheel is rolled over non-pressable things inside it, like text or images.
- If the frontmost is a pressable node, the first scroll view in that node and its parent chain receives it. (Overlays or windows covering a scroll view block the wheel)
- true if a view received it.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
- wheelDeltaVector2
- 휠 값. (스크롤 칸의 wheel 에 그대로 넘긴다)Wheel amount. (passed as is to the scroll view's wheel)
반환Returnsboolean 휠을 받은 스크롤 칸이 있으면 참.True if a scroll view received the wheel.
그 자리에서 휠을 받을 스크롤 칸 찾기. (touchWheel 의 셈, 없으면 null)
- raycast 와 같은 순서로 돌며 누를 수 있는 노드와 스크롤 칸 노드 가운데 가장 앞을 고른다.
Finds the scroll view that receives the wheel at that point. (touchWheel's computation, null if none)
- Iterates in the same order as raycast and picks the frontmost among pressable nodes and scroll view nodes.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
반환Returnsobject | null 휠을 받을 스크롤 칸 컴포넌트. (없으면 null)The scroll view component to receive the wheel. (null if none)
노드에 붙은 스크롤 칸 컴포넌트 반환. (켜진 것만, 없으면 null, 닥 타이핑)
Returns the scroll view component attached to the node. (Enabled ones only, null if none, duck typing)
- nodeWorldNode
- 볼 노드.Node to look at.
반환Returnsobject | null 켜진 스크롤 칸 컴포넌트. (없으면 null)The enabled scroll view component. (null if none)
hitNode 자기 자신을 포함해 부모 체인에서 가장 가까운 UIScrollView 를 찾는다. (TouchRecognizer 의 findAncestorScrollView 와 다른 점: target 자신도 후보)
- UIScrollView import 를 피하기 위해 컴포넌트 타입은 닥 타이핑으로 검사한다.
Finds the nearest UIScrollView in the parent chain, including hitNode itself. (Difference from TouchRecognizer's findAncestorScrollView: target itself is also a candidate)
- To avoid importing UIScrollView, the component type is checked by duck typing.
- targetWorldNode
- 찾기 시작할 노드. (자신도 후보)Node to start the search from. (itself is also a candidate)
반환Returnsobject | null 찾은 스크롤 칸 컴포넌트. (없으면 null)The found scroll view component. (null if none)
레이캐스트.
- 루트 노드로부터 draw() 호출 순서대로 번호를 매기며 순회한다.
- 활성화 상태이고 isInteractable()이 참이며 터치 좌표를 포함하는 노드 중 가장 높은 번호의 노드를 반환한다. (노드 종류는 가리지 않는다)
- Mask 가 붙은 노드의 자손은 그 노드 영역 안에서만 맞는다. (잘려 보이지 않는 곳은 눌리지 않는다)
Raycast.
- Traverses from the root node, numbering in draw() call order.
- Returns the highest-numbered node among the nodes that are active, whose isInteractable() is true and that contain the touch coordinates. (node types are not restricted)
- Descendants of a node with a Mask hit only within that node's area. (Clipped, invisible areas are not pressed)
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
반환ReturnsWorldNode | null 그 자리를 품은 가장 앞의 누를 수 있는 노드. (없으면 null)The frontmost interactable node containing that position. (null if none)
Mask 가 붙은 노드인데 좌표가 그 영역 밖인지.
Whether the node has a Mask and the coordinates are outside its area.
- nodeWorldNode
- 볼 노드.Node to look at.
- viewInputPositionVector2
- 뷰 좌표의 입력 위치.Input position in view coordinates.
반환Returnsboolean 켜진 Mask 가 붙어 있고 그 자리가 노드 밖이면 참.True if an enabled Mask is attached and the position is outside the node.
루트 노드 설정.
Sets the root node.
- rootNode*
- 훑을 루트 노드. (보통 씬의 루트)Root node to traverse. (usually the scene root)
루트 노드 반환.
Returns the root node.
반환Returns* 훑는 루트 노드. (정하지 않았으면 null)The root node being traversed. (null if not set)
현재 터치 대상 반환.
Returns the current touch target.
반환ReturnsWorldNode | null 누를 때 맞은 노드. (뗐거나 없으면 null)The node hit on press. (null after release or if none)
짝Counterpart: vanilla-engine SceneBase.get_touch_target
한 번이라도 터치된 적 있는지 반환.
Returns whether it has ever been touched.
반환Returnsboolean 한 번이라도 눌렀으면 참.True if pressed at least once.
짝Counterpart: vanilla-engine SceneBase.has_ever_touched
첫 터치 콜백 설정.
Sets the first touch callback.
- callbackFunction
- 처음 누를 때 한 번 부를 함수. (인자 없음)Function called once on the first press. (no arguments)
짝Counterpart: vanilla-engine SceneBase.set_first_touch_callback