11package JavaGameEngine .Components ;
22
3- import JavaGameEngine .Backend .ComponentHandler ;
3+ import JavaGameEngine .Backend .GameWorld ;
44import JavaGameEngine .Backend .Input .Input ;
55import JavaGameEngine .Backend .UpdateThread ;
6- import JavaGameEngine .Components .Collider .Collider ;
7- import JavaGameEngine .Components .Collider .SquareCollider ;
8- import JavaGameEngine .Components .Physics .PhysicsBody ;
9- import JavaGameEngine .msc .Debug ;
106import JavaGameEngine .msc .Vector2 ;
117
128import java .awt .*;
139import java .util .LinkedList ;
10+ import java .util .Objects ;
1411
1512public class Component {
1613
17- Vector2 position = Vector2 . zero ; // world position
14+ Vector2 position ; // world position
1815 Vector2 localPosition =Vector2 .zero ; // local position this is that children to a parent should change to change position
1916 Vector2 cameraPosition = Vector2 .zero ; // camera offset
2017
21- Vector2 scale = Vector2 . zero ; // scale with,height
18+ Vector2 scale ; // scale with,height
2219 Vector2 localScale =Vector2 .zero ; // local scale with,height
2320
2421 Vector2 rotation =Vector2 .zero ; // rotation
@@ -34,6 +31,7 @@ public int getLayer() {
3431 }
3532
3633 public void setLayer (int layer ) {
34+ GameWorld .layerList .add (this );
3735 this .layer = layer ;
3836 }
3937
@@ -90,7 +88,7 @@ public Vector2 getPosition() {
9088 return position ;
9189 }
9290 public void setPosition (Vector2 position ) {
93- if (this .tag != "player" ){
91+ if (! Objects . equals ( this .tag , "player" ) ){
9492 this .position = position ;
9593 }
9694 else {
@@ -225,22 +223,20 @@ public void destroy(){
225223 * this is the update function. It will be called on every game update
226224 */
227225 public void update () {
228-
229- if (insideComp ()&&isEnabled ()){
230- if (!isMouseInside ()){
231- onMouseEntered ();
232- setMouseInside (true );
226+ if (insideComp () && isEnabled ()) {
227+ if (!isMouseInside ()) {
228+ onMouseEntered ();
229+ setMouseInside (true );
230+ }
231+
232+ } else if (isMouseInside () && isEnabled ()) {
233+ onMouseExit ();
234+ setMouseInside (false );
235+ }
236+ if (isMouseInside () && Input .isMousePressed () && isEnabled ()) {
237+ onMousePressed ();
238+ if (getParent () != null ) getParent ().onMousePressed ();
233239 }
234-
235- }
236- else if (isMouseInside ()&&isEnabled ()){
237- onMouseExit ();
238- setMouseInside (false );
239- }
240- if (isMouseInside ()&&Input .isMousePressed ()&&isEnabled ()){
241- onMousePressed ();
242- if (getParent ()!=null ) getParent ().onMousePressed ();
243- }
244240
245241 if (parent !=null ) {
246242 float x = (parent .getPosition ().getX ()-((getScale ().getX ()/2 )));
@@ -272,10 +268,7 @@ private boolean insideComp(){
272268 float mx = Input .getMousePosition ().getX ();
273269 float my = Input .getMousePosition ().getY ();
274270
275- if (mx >xMin &&mx <xMax &&my >yMin &&my <yMax ){
276- return true ;
277- }
278- return false ;
271+ return mx > xMin && mx < xMax && my > yMin && my < yMax ;
279272 }
280273 public void updateChildren (){
281274 LinkedList <Component > s = getChildren ();
0 commit comments