Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/scene/2d/parallax_2d.h
9903 views
1
/**************************************************************************/
2
/* parallax_2d.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "scene/2d/node_2d.h"
34
35
class Parallax2D : public Node2D {
36
GDCLASS(Parallax2D, Node2D);
37
38
static constexpr real_t DEFAULT_LIMIT = 10000000;
39
40
String group_name;
41
Size2 scroll_scale = Size2(1, 1);
42
Point2 scroll_offset;
43
Point2 screen_offset;
44
Vector2 repeat_size;
45
int repeat_times = 1;
46
Point2 limit_begin = Point2(-DEFAULT_LIMIT, -DEFAULT_LIMIT);
47
Point2 limit_end = Point2(DEFAULT_LIMIT, DEFAULT_LIMIT);
48
Point2 autoscroll;
49
bool follow_viewport = true;
50
bool ignore_camera_scroll = false;
51
52
void _update_process();
53
void _update_repeat();
54
void _update_scroll();
55
56
protected:
57
#ifdef TOOLS_ENABLED
58
void _edit_set_position(const Point2 &p_position) override;
59
#endif // TOOLS_ENABLED
60
void _validate_property(PropertyInfo &p_property) const;
61
void _camera_moved(const Transform2D &p_transform, const Point2 &p_screen_offset, const Point2 &p_adj_screen_offset);
62
void _notification(int p_what);
63
static void _bind_methods();
64
65
public:
66
void set_scroll_scale(const Size2 &p_scale);
67
Size2 get_scroll_scale() const;
68
69
void set_repeat_size(const Size2 &p_repeat_size);
70
Size2 get_repeat_size() const;
71
72
void set_repeat_times(int p_repeat_times);
73
int get_repeat_times() const;
74
75
void set_autoscroll(const Point2 &p_autoscroll);
76
Point2 get_autoscroll() const;
77
78
void set_scroll_offset(const Point2 &p_offset);
79
Point2 get_scroll_offset() const;
80
81
void set_screen_offset(const Point2 &p_offset);
82
Point2 get_screen_offset() const;
83
84
void set_limit_begin(const Point2 &p_offset);
85
Point2 get_limit_begin() const;
86
87
void set_limit_end(const Point2 &p_offset);
88
Point2 get_limit_end() const;
89
90
void set_follow_viewport(bool p_follow);
91
bool get_follow_viewport();
92
93
void set_ignore_camera_scroll(bool p_ignore);
94
bool is_ignore_camera_scroll();
95
96
Parallax2D();
97
};
98
99