semperhilaris / smoothcam Goto Github PK
View Code? Open in Web Editor NEWSmooth Camera for 2D Games (libGDX Demo included)
License: MIT License
Smooth Camera for 2D Games (libGDX Demo included)
License: MIT License
In a scenario where SmoothCamPoints
are added and removed frequently, SmoothCamWorld
would unnecessarily take too much memory and GC time. This can happen for example on games where the player is a vehicle moving through a big map and we wish to maintain the SmoothCamPoint count low. The problem is in SmoothCamWorld
addPoint
and removePoint
methods:
private SmoothCamPoint[] points = {};
public void addPoint (SmoothCamPoint point) {
SmoothCamPoint[] newPoints = new SmoothCamPoint[points.length + 1];
newPoints[0] = point;
System.arraycopy(points, 0, newPoints, 1, points.length);
points = newPoints;
}
public void removePoint (SmoothCamPoint point) {
ArrayList<SmoothCamPoint> temp = new ArrayList<SmoothCamPoint>(Arrays.asList(points));
temp.remove(point);
points = temp.toArray(new SmoothCamPoint[temp.size()]);
}
I think the memory allocation on both methods is completely unacceptable, so a general fix is needed. For a LibGDX application, I would suggest using com.badlogic.gdx.utils.Array
to store the SmoothCamPoint
instances:
private Array<SmoothCamPoint> points = new Array<SmoothCamPoint>(false, 25, SmoothCamPoint.class);
public void addPoint (SmoothCamPoint point) {
points.add(point);
}
public void removePoint (SmoothCamPoint point) {
points.removeValue(point, false);
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.