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
Added a Scene2DDebugRenderer #2011
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8eac24b
Added a Scene2DDebugRenderer.
nooone a4eed12
Made colours configurable.
nooone 6c8d593
Table debug rendering included.
nooone 6ea8293
Small JavaDoc change.
nooone 0cffe3c
Actors now know themselves how to debug render. Adjusted all tests. A…
nooone 27657c1
Conflicts resolved.
nooone 9e8654d
Removed an unused method.
nooone 3ddad49
Small bugfix and renamed fields.
nooone 0bf494a
Removed the final modifiers for colors.
nooone 3c6c1aa
Fix merge conflict.
nooone 3335ae7
Added entry to CHANGES
nooone File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ | |
import com.badlogic.gdx.scenes.scene2d.InputEvent.Type; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ActorGestureListener; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ClickListener; | ||
import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer; | ||
import com.badlogic.gdx.scenes.scene2d.utils.Scene2DDebugRenderer.DebugRect; | ||
import com.badlogic.gdx.scenes.scene2d.utils.ScissorStack; | ||
import com.badlogic.gdx.utils.Array; | ||
import com.badlogic.gdx.utils.DelayedRemovalArray; | ||
|
@@ -65,6 +67,9 @@ public class Actor { | |
final Color color = new Color(1, 1, 1, 1); | ||
private Object userObject; | ||
|
||
private boolean debuggingEnabled = true; | ||
public static Color debugColor = new Color(0, 1, 0, 1); | ||
|
||
/** Draws the actor. The Batch is configured to draw in the parent's coordinate system. | ||
* {@link Batch#draw(com.badlogic.gdx.graphics.g2d.TextureRegion, float, float, float, float, float, float, float, float, float) | ||
* This draw method} is convenient to draw a rotated and scaled TextureRegion. {@link Batch#begin()} has already been called on | ||
|
@@ -379,16 +384,16 @@ public void setPosition (float x, float y) { | |
} | ||
|
||
/** Set position of Actor centered on x, y */ | ||
public void setCenterPosition(float x, float y) { | ||
public void setCenterPosition (float x, float y) { | ||
this.x = x - width / 2; | ||
this.y = y - height / 2; | ||
} | ||
|
||
public float getCenterX() { | ||
public float getCenterX () { | ||
return this.x + width / 2; | ||
} | ||
|
||
public float getCenterY() { | ||
public float getCenterY () { | ||
return this.y + height / 2; | ||
} | ||
|
||
|
@@ -554,8 +559,7 @@ public Color getColor () { | |
return color; | ||
} | ||
|
||
/** Retrieve custom actor name set with {@link Actor#setName(String)}, | ||
* used for easier identification */ | ||
/** Retrieve custom actor name set with {@link Actor#setName(String)}, used for easier identification */ | ||
public String getName () { | ||
return name; | ||
} | ||
|
@@ -566,6 +570,28 @@ public void setName (String name) { | |
this.name = name; | ||
} | ||
|
||
/** The {@link Scene2DDebugRenderer} will ask every actor of a stage for their debugging rectangles. To fill the given array you | ||
* can obtain fresh {@link DebugRect}s via the {@link Scene2DDebugRenderer#debugRectPool}. To avoid the garbage collection you | ||
* should make sure to free them later, but it's not a strict requirement. */ | ||
public void getDebugRects (Array<DebugRect> debugRects) { | ||
DebugRect debugRect = Scene2DDebugRenderer.debugRectPool.obtain(); | ||
debugRect.bottomLeft.set(0, 0); | ||
debugRect.topRight.set(width, height); | ||
debugRect.color.set(Actor.debugColor); | ||
debugRects.add(debugRect); | ||
} | ||
|
||
/** Used only in combination with a {@link Scene2DDebugRenderer}. It does only influence this particular actor, not its | ||
* children, in case we have a {@link Group}. */ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note the first sentence is used for the summary in javadocs, so should describe the method succinctly. Subsequent sentences can give more details. /pedantic :) |
||
public void setDebuggingEnabled (boolean enabled) { | ||
debuggingEnabled = enabled; | ||
} | ||
|
||
/** Used only in combination with a {@link Scene2DDebugRenderer}. */ | ||
public boolean isDebuggingEnabled () { | ||
return debuggingEnabled; | ||
} | ||
|
||
/** Changes the z-order for this actor so it is in front of all siblings. */ | ||
public void toFront () { | ||
setZIndex(Integer.MAX_VALUE); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Who should free them and when? If they are from Scene2DDebugRenderer.debugRectPool can't they be freed automatically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm shuffling things around slightly, please hold. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't have a look at the refactored code yet, but the custom
Actor
should free them, whenever they want to. I wasn't able to free them automatically (for example after rendering them inScene2DDebugRenderer
, becauseTable
keeps them for a longer time.