vanilladocs
vanillapunch.com
API / core/touchraycaster

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.).
예제Example씬의 누름을 맨 앞 노드에 넘기기Pass scene presses to the frontmost node
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());
생성자constructorconstructor()#0.1.0 부터since 0.1.0소스source

생성.

Constructor.

메서드methodtouchPress(viewInputPosition)#0.1.0 부터since 0.1.0소스source

터치 누름.

  • raycast로 대상을 결정하고 touchPress를 전달한다.

Touch press.

  • Determines the target with raycast and delivers touchPress.
viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchMove(viewInputPosition)#0.1.0 부터since 0.1.0소스source

터치 이동.

  • press 시 결정된 대상에 touchMove를 전달한다.

Touch move.

  • Delivers touchMove to the target determined at press.
viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchRelease(viewInputPosition)#0.1.0 부터since 0.1.0소스source

터치 뗌.

  • press 시 결정된 대상에 touchRelease를 전달하고 대상을 해제한다.

Touch release.

  • Delivers touchRelease to the target determined at press and releases the target.
viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchCancel(viewInputPosition)#0.1.0 부터since 0.1.0소스source

터치 취소.

  • press 시 결정된 대상에 touchCancel을 전달하고 대상을 해제한다.

Touch cancel.

  • Delivers touchCancel to the target determined at press and releases the target.
viewInputPositionVector2
뷰 좌표의 입력 위치.Input position in view coordinates.
메서드methodtouchWheel(viewInputPosition, wheelDelta)#0.2.1 부터since 0.2.1소스source

마우스 휠. (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.

메서드methodfindWheelScrollView(viewInputPosition)#0.4.0 부터since 0.4.0소스source

그 자리에서 휠을 받을 스크롤 칸 찾기. (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)

메서드methodfindScrollViewComponent(node)#0.4.0 부터since 0.4.0소스source

노드에 붙은 스크롤 칸 컴포넌트 반환. (켜진 것만, 없으면 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)

메서드methodfindAncestorScrollViewForWheel(target)#0.2.1 부터since 0.2.1소스source

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)

메서드methodraycast(viewInputPosition)#0.1.0 부터since 0.1.0소스source

레이캐스트.

  • 루트 노드로부터 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)

메서드methodisMaskedOut(node, viewInputPosition)#0.3.2 부터since 0.3.2소스source

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.

메서드methodsetRootNode(rootNode)#0.1.0 부터since 0.1.0소스source

루트 노드 설정.

Sets the root node.

rootNode*
훑을 루트 노드. (보통 씬의 루트)Root node to traverse. (usually the scene root)
메서드methodgetRootNode()#0.1.0 부터since 0.1.0소스source

루트 노드 반환.

Returns the root node.

반환Returns* 훑는 루트 노드. (정하지 않았으면 null)The root node being traversed. (null if not set)

메서드methodgetTouchTarget()#0.1.0 부터since 0.1.0소스source

현재 터치 대상 반환.

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

메서드methodhasEverTouched()#0.2.0 부터since 0.2.0소스source

한 번이라도 터치된 적 있는지 반환.

Returns whether it has ever been touched.

반환Returnsboolean 한 번이라도 눌렀으면 참.True if pressed at least once.

짝Counterpart: vanilla-engine SceneBase.has_ever_touched

메서드methodsetFirstTouchCallback(callback)#0.2.0 부터since 0.2.0소스source

첫 터치 콜백 설정.

Sets the first touch callback.

callbackFunction
처음 누를 때 한 번 부를 함수. (인자 없음)Function called once on the first press. (no arguments)

짝Counterpart: vanilla-engine SceneBase.set_first_touch_callback