I am trying to move a sprite from the top to bottom of the screen but I do not have any success at this moment... I've used the following as example.
In this case, the sprites, are moving from left to right, and in my case I want to move them from top to bottom.
Can anyone give me a help on this?
How can I proceed to make this work?
Use CCMoveToAction for moving a sprite.
For the movement of sprite from top to bottom
//to get total size of display
CGSize winSize = CCDirector.sharedDirector().displaySize();
CCMoveTo moveTo = CCMoveTo.action(1,
CGPoint.ccp(width, ));
Related
I have two ImageViews inside a constraint layout. One on top and one on bottom. I want to move the bottom one onto the top one. Of course I know it doesn't change it's actual position which I am ok with. When I use TranslateAnimation to move to the specified coordinates the image goes down and to the right instead of moving up and to the right. Also when it moves to the right it is slightly off. I can use view.animate().y(getTop).x(getLeft); and it moves the image into the correct position but then it is stuck there. I can't get it to move back to its original like it would if fillAfter was false.
First I get the destination location
float x = playerOneCard.getLeft();
float y = playerOneCard.getTop();
This code moves the card to the correct location but does not reset it after being moved. I need it to essentially move there, go back to it's original place, and repeat as many times as the button is pressed.
playerOneCardMove.animate().x(x).y(y);
This code moves the image but down and towards the right no where close to lining up with the desired destination.
TranslateAnimation translateAnimation = new
TranslateAnimation(Animation.ABSOLUTE,x,Animation.ABSOLUTE,y);
translateAnimation.setDuration(500);
translateAnimation.setFillAfter(false);
playerOneCardMove.startAnimation(translateAnimation);
Figured it out. Since I was going from the absolute position of the first image the top left of that image is 0,0. So it was moving accordingly. Instead I measured the distance from the top of the image on the bottom to the top of the image above it and then moved it according to distance. I did the same for both x and y coordinates.
float distanceY = Math.abs(playerOneCardMove.getTop() - playerOneCard.getTop());
float distanceX = Math.abs(playerOneCard.getLeft() - playerOneCardMove.getLeft());
TranslateAnimation translateAnimation = new TranslateAnimation(Animation.ABSOLUTE,distanceX ,Animation.ABSOLUTE,(distanceY) - (distanceY*2));
translateAnimation.setDuration(1000);
translateAnimation.setFillAfter(false);
playerOneCardMove.startAnimation(translateAnimation);
Hope this helps someone else.
Is there any way to limit the scroll area of AChartEngine? I have a graph of stats for a team where the X-axis represents time and the Y-axis represents score and it doesn't make sense to have negative for either. I'd like to make it so that the farthest that the user can scroll down and to the left would put the origin in the bottom left corner of the screen. I appreciate any assistance.
Try using setPanLimits() method ..
double[] panLimits={0,10,0,50}; // [panMinimumX, panMaximumX, panMinimumY, panMaximumY]
mRenderer2.setPanLimits(panLimits);
where mRenderer2 is XYMultipleSeriesRenderer .
hi I'm working with the animations, I currently have 4 directional buttons, depending on which button I press, the image will move in that direction. My problem is so that the image goes beyond the edges of the screen, and I have no idea how to do it xD. For the animation use this ObjectAnimator objectAnimator= ObjectAnimator.ofFloat(IMG3, "translationX", Position_Start,Position_End);
Of course! All you need to do is get the size of the screen in pixels (see here). the top left corner of the screen will be (0,0) and the bottom right will be your output from one of the functions provided.
Then, all you need to do is get the position of your view (animation) using View.getLocationOnScreen() and/or getLocationInWindow() to get the top left corner and using View.getWidth() and View.getHeight() to get the size of your view.
The final step is to make sure that View.getLocationOnScreen() is never less than (0,0) and View.getLocationOnScreen() + (getWidth(),getHeight()) is always less than display.getSize(size), or whatever method you use to get screen size.
I am making a sprite at a certain location and I want to scale it down. Here is the code that I am using:
sp_nest_r4 = new Sprite(460f, 720f, txRg_nest_maroon);
sp_nest_r4.setScaleCenter(sp_nest_r4.getX(), sp_nest_r4.getY());
sp_nest_r4.setScale(0.454545f);
bdy_nest_r4 = PhysicsFactory.createCircleBody(mPhysicsWorld, sp_nest_r4, BodyType.StaticBody, fxd_spring);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(sp_nest_r4, bdy_nest_r4, true, true));
sp_nest_r4.setUserData(bdy_nest_r4);
mScene.attachChild(sp_nest_r4);
Now the problem is that when I set the scale center, the sprite doesn't show and gets disappeared. But if I remove the line sp_nest_r4.setScaleCenter(sp_nest_r4.getX(), sp_nest_r4.getY()); , the sprite shows up, but its position is slightly shifted towards right & downwards than the original specified position.
I can't figure out this behavior, same is the case if I scale up the sprite.
It looks like you are trying to use scene coordinates instead of local coordinates.
If I remember correctly, you should provide local coordinates in case of setScaleFunction, try to do like following:
sp_nest_r4.setScaleCenter(0,0); //upper left corner of sprite
how to set the screen coordinate system of android screen as first Quadrant of the XY plane
,iwant the (0,0) position to be at bottom left , and i wanna know if i can use the trignometric equation on android screen as Android XY plane is not like the Xy plane
I don't think there's a way to do it that would affect the entire system, such as the XML layout files. But if you just want to draw with a Canvas, you can use translate() and scale().
First use translate() to slide the canvas down so 0,0 is at the bottom. Now the top of the screen would be a negative number, so call scale() to flip it around. Now 0,0 is still at the bottom, and the top of the screen is a positive number.
I'm working with information from this answer and its comments. Use something like:
canvas.save(); // need to restore after drawing
canvas.translate(0, canvas.getHeight()); // reset where 0,0 is located
canvas.scale(1, -1); // invert
... // draw to canvas here
canvas.restore(); // restore to normal
And yes, you can use normal 2D trigonometric functions with the XY coords. You can do it even if they're not translated, you just have to think it through more carefully.
I don't know that you're going to have much luck changing where (0,0) is located, but you could set a constant that accounts for such. myY = y minus screenHeight so (x, myY) adjusts y to the bottom of the screen and works from there +/-.
look up canvas.scale(xs,ys,xp,yp)
xp and yp are the new coordinates that you set for your (0,0) point.