I want my sprite to move from one point to another point in a curve path, so i am using Bezierto in my code, but it doesnt seems to work out as it shows an error on bezier keyword
(The local variable bezier may not have been initialized). please help me.
my code is as follows
//initial point of sprite
sprite1pos=CGPoint.ccp((winSize.width/2+winSize.width/2),0);
//now the bezier config declaration
CCBezierConfig bezier;
bezier.controlPoint_1=CGPoint.ccp(sprite1pos.x,sprite1pos.y);
bezier.controlPoint_2=CGPoint.ccp(winSize.width/2,winSize.height/2);
bezier.endPosition=CGPoint.ccp(0,0);
CCBezierTo action = CCBezierTo.action(3, bezier);
sprite1.runAction(action);
You need to initialize your bezier variable.
The line :
CCBezierConfig bezier;
Does not initialize the bezier variable.
It should be :
CCBezierConfig bezier = new CCBezierConfig(<arguments if any>);
Related
I'm using the SymbolManager to display two symbols on the map. Here is an example:
The dark symbol is because of the fact that I'm testing the project on the Emulator, but the Line goes under the symbol, as it should be. The problem comes with the other symbol (finish flag). After I'm ready with the drawing of the line, the following code block is called:
symbolManager = new SymbolManager(mapView,mMapboxMap,style);
symbolManager.setIconAllowOverlap(true);
symbolManager.setIconIgnorePlacement(true);
SymbolOptions symbolOptionsFinishFlag = new SymbolOptions()
.withIconImage(IMAGE_FINISH_FLAG)
.withIconSize(2.0f)
.withLatLng(newLatLngs.get(newLatLngs.size()-1));
symbolManager.create(symbolOptionsFinishFlag);
LatLngBounds.Builder builder = new LatLngBounds.Builder();
builder.includes(newLatLngs);
LatLngBounds bounds = builder.build();
final CameraUpdate cu = new CameraUpdateFactory().newLatLngBounds(bounds,300);
mMapboxMap.easeCamera(cu,5000);
I checked some examples in the Mapbox site and it seems to be correct. However, the Symbol is under the Line, how can I bring on top of it?
If you are using a LineLayer, when adding it to the map use style.addLayerBelow(lineLayer, symbolManager.layerId)
This answer is about how to do this in Mapbox SDK v9. All AnnotationManager subclasses have a constructor which allows you to mention which layerId this should be below.
For example, in LineManager, we have this constructor
LineManager(MapView mapView, MapboxMap mapboxMap, Style style, java.lang.String belowLayerId)
Another method which will be needed here is the getLayerId method in the AnnotationManager class which returns the id used by a certain layer.
getLayerId
public java.lang.String getLayerId()
Returns a layer ID that annotations created by this manager are laid out on. This reference can be used together with Style#addLayerAbove(Layer, String) or Style#addLayerBelow(Layer, String) to improve other layers positioning in relation to this manager.
Returns:
underlying layer's ID
So say there are 3 elements on the map, a circle, a line and a symbol and we need to show the circle at the bottom, then the line above and finally the symbol at the top most.
So we will create our AnnotationManagers in this way -
val symbolManager = SymbolManager(mapView, map, map.style!!)
val lineManager = LineManager(mapView, map, map.style!!, symbolManager.layerId)
val fillManager = FillManager(mapView, map, map.style!!, lineManager.layerId)
What we're doing here is that while creating the lineManager object, we pass the layerId of the symbolManager which ensures that the Lines created using LineManager are always below the Symbols created using the SymbolManager. And the same for FillManager being below the lineManager object.
Although SymbolManagers can be useful means for providing an abstraction over the methods needed to add symbols to a map, you may get some more flexibility by working with native SymbolLayers directly. This example shows how to add symbol layer icons to a map, and this example shows how to specify layer ordering when new layers are added. So, by adding two symbol layers for your start and finish icons, and a line layer for the line between them, you could use style.addLayerBelow(finishFlagLayer, "name_of_line_layer").
I have 2 classes; A and B.
A is the character class, it contains every character detail (position...)
B is the class which get the A class and render. I need to create another object when I touch the screen. I got it, the class seems containing the new values but it doesn't renderize them.
for (A a: aa) {
shapeRenderer.begin(ShapeType.Filled);
shapeRenderer.setColor(Color.RED);
shapeRenderer.circle(a.getBoundingCircle().x, a.getBoundingCircle().y, a.getBoundingCircle().radius);
shapeRenderer.end();
}
is recommended use best names.
are you sure a.getBoundingCircle() cotains the correct data, and are you sure had objects A in aa and your program join inside the for?
and i dont look b
Ok, your problem is the new values dont be renderized.
Two options:
You not are running the loop for render the objects.
Your new values are out of the screen.
When you get the position of the touch events you get the screenx and the screeny, not the game camera coordenates, and you need convert it with unproject.
For example:
Vector3 touchPos = new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0);
camera.unproject(touchPos);
touchPos now is in the game coordenates.
I'm using LibGDX for my Android app. I need to move and orient 3D object(ModelInstance) along a spline.In my case it's CatmullRomSpline. I got the movement working but having problem with orienting the ModelInstance along the spline.
My Code:
public void update() {
float t = SPEED * Gdx.graphics.getDeltaTime();
elapsedTime = elapsedTime + SPEED * Gdx.graphics.getDeltaTime();
//Movement
catmull.valueAt(value, elapsedTime);
myObject3d.transform.setTranslation(value);
//Rotation
derivative = catmull.derivativeAt(derivative, t);
derivative = derivative.nor();
//Tried to bring object into default position before rotating
//Vector.X - is the default direction of my Object - facing right
//myObject3d.transform.rotate(Vector3.X, Vector3.X);
myObject3d.transform.rotate(derivative, Vector3.X);
}
The Matrix4#rotate method has two arguments, base and target. In your case the base vector should be Vector3.X, while the target is derivative. You need to swap the arguments for this. Also, the Matrix4#rotate method post-multiplies the rotation on top the existing rotation. Or in other words: this will accumulate the absolute rotation on every call. You probably want to use the Matrix4#setToRotation method instead, which resets the rotation on every call (clears the matrix).
myObject3d.transform.setToRotation(Vector3.X, derivative);
myObject3d.transform.setTranslation(value);
While this probably will work in most cases, you might get unexpected results depending on the path. Like said, there are infinite possible rotations that will result in this direction. Therefor it's better to use two additional vectors to specify the up (Y) and right (Z) vector.
right.set(Vector3.Y).crs(derivative).nor();
up.set(right).crs(derivative).nor();
myObject3d.transform.set(derivative, up, right, position).rotate(Vector3.X, 180);
Here the cross product is used to calculate the right and up vectors, where it is assumed that Vector3.Y is usually close to the up vector. Then the Matrix4#set method is used to set the matrix to reflect these values. The first argument specifies the "new" X-axis, the second the "new" Y-axis, the third the "new" Z-axis and the last argument specifies the translation (location).
Here's a working example: https://gist.github.com/xoppa/7558c0c75e9534795e9f
Although unrelated, keep in mind that path.valueAt method uses 0 <= t <= 1. Or in other words, t (elapsedTime in your code) should not be below 0 or above 1.
is there any example, howto place any of charts in MPAndroidChart library to homescreen widget?
//i tried to use getChartbitmap(), but
1)bitmap is not created immediately after calling invalidate(), so it return null
2)i dont see way, howto initialize chart class without placing resources - which i cant do
for widget.
anybody have some successful example ?
The chart needs some milliseconds to draw the content onto the Bitmap. That is the reason why calling getChartBitmap() right after invalidate() will not return a valid Bitmap.
Try using a Handler and delay the time before retrieving the Bitmap by abound 100ms.
Try this code
BarData chartData =...
BarChart chart = new BarChart(mContext);
chart.setData(chartData);
chart.measure(View.MeasureSpec.makeMeasureSpec(300,View.MeasureSpec.EXACTLY),
View.MeasureSpec.makeMeasureSpec(500,View.MeasureSpec.EXACTLY));
chart.layout(0, 0, chart.getMeasuredWidth(), chart.getMeasuredHeight());
Bitmap chartBitmap = chart.getChartBitmap();
In Activity with chart, function getChartBitmap() working fine! It's return bitmap without any errors. IMHO that's the problem, in widget we don't have an activity, placing created chart in layout is not take effect :( So, we can't have a widget with this chart at all, and it's very sad - this chart so really cool.
I've been struck hard with an issue with the path class that is used to draw smooth lines on canvas with the canvas.drawPath(path,paint) function . Path class is useful for smoothing out lines with the path.quadTo() and cubeTo() function . But they do not let you draw a smoothed out line with varying thickness . I want to draw a Path on the canvas with increasing thickness up to a certain threshold width and then slim out at the end . Also i tried using a number of paths at every touch point of user but that fails when the user moves his finger really fast , because at that time a single path of a long length is obtained . Please help me i am in big trouble with this . Is there any other way of smoothing out lines .
Thank You
I think you are asking how to vary the width of the Path that is drawn using the canvas.drawPath() method. The following code snippet should help you regarding that:
private Paint myPaint;
myPaint.setStyle(Paint.Style.STROKE);
myPaint.setStrokeJoin(Paint.Join.ROUND);
myPaint.setStrokeCap(Paint.Cap.ROUND);
if(someFlag != thresholdValue)
myPaint.setStrokeWidth(20);
else
{
myPaint.setStrokeWidth(someReducedValue); // or have a counter updated in your thread to regularly decrement the value
}
//..
..//
canvas.drawPath(path, myPaint); // inside onDraw() where path corresponds to your Path variable
The correct way to do this is to use the PathMeausre class , where we can easily get subPaths from a prent path and manuplate them accordingly . When i ll be done with the code ,i ll post the snippet soon.