I have android ics-x86 and i need to simulate drag event but device.drag is giving error
it is giving me class cast exception.i have called it like this-
x=(67.8,100.0)
y=(267.8,100.0)
device.drag(x,y,10.0,10)
what is wrong with the arguments??please help!
device.drag (tuple start, tuple end, float duration, integer steps)
example: device.drag((350, 620), (13, 620), 0.5, 50)
Related
I've got an animation to perform which consists of some arrow heads aligned horizontally where the alpha values of the arrows will change to achieve an animation effect (i.e. first arrow has alpha 1.0, then the second will get a value 1.0 etc.).
So if I have a function like this:
void highlightFirstArrow()
{
mArrow1.setAlpha(1.0f);
mArrow2.setAlpha(0.75f);
mArrow3.setAlpha(0.50f);
mArrow4.setAlpha(0.20f);
}
Then I'd want to start, repeat numerous times, then stop a function such as this:
void animateArrows()
{
highlightFirstArray();
pause;
highlightSecondArray();
pause;
etc.
}
Obviously this would lock up the GUI thread if it were performed in a for look for example. What are the options for achieving the desired animiation:
- run a for loop in a separate thread
- don't use a loop, instead constantly execute the functions individually via a timer
- use built in specific android animation mechanisms. If so which is most appropriate? Would AnimatorSet() be good for this scenario, or something else
You definitely shouldn't use any loops or timers. There're lots of built in classes which could help to animate your views. For instance you can use ValueAnimator:
ValueAnimator.ofFloat(1f, 0.2f).setDuration(1000).addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override public void onAnimationUpdate(ValueAnimator animation) {
float value = (float) animation.getAnimatedValue();
arrow1.setAlpha(value);
arrow2.setAlpha(value);
}
});
Im using this code to get the direction of a throw:
throwDirection = -(Camera.main.WorldToScreenPoint(hookedObject.transform.position) -
Input.mousePosition)/(Camera.main.WorldToScreenPoint(hookedObject.transform.position) -
Input.mousePosition).magnitude;
My problem is when i try to translate this to work with touch, it gives me this error:
error CS0121: The call is ambiguous between the following methods or properties: UnityEngine.Vector2.operator -(UnityEngine.Vector2, UnityEngine.Vector2) and UnityEngine.Vector3.operator -(UnityEngine.Vector3, UnityEngine.Vector3)
Here is the touch version of the code, it basically just replaces Input.mousePosition with Input.GetTouch(0).position:
throwDirection = -(Camera.main.WorldToScreenPoint(hookedObject.transform.position) -
Input.GetTouch(0).position)/(Camera.main.WorldToScreenPoint(hookedObject.transform.position)
- Input.GetTouch(0).position).magnitude;
Im confused why this error is occuring. Im using a vector2 for the mouse position, and a vector 2 for the touch positions. Yet this error only occurs on the touch version of the code? It appears twice for everytime i try to use Input.GetTouch(0).position.
When i try to save Input.GetTouch(0).position to a variable the same error occurs. But it only occurs when i use the variable, not when i store the variable.
For instance:
Vector2 touchPos = Input.GetTouch(0).position;
This doesnt give me the error however if i try to use this variable in another statement, the error occurs.
hookedObject.transform.position is Vector3 while Input.GetTouch(0).position is Vector2.
mousePosition is actually also Vector3 which is why that code did work.
It is possible to cast Vector2 to Vector3 and vice versa which is why its ambiguous. Casting touch to Vector3 should fix your problem.
throwDirection = -
(Camera.main.WorldToScreenPoint(hookedObject.transform.position) - (Vector3)
Input.GetTouch(0).position)/(Camera.main.WorldToScreenPoint(hookedObject.transform.position)
- (Vector3)Input.GetTouch(0).position).magnitude;
Input.GetTouch(0).position is a Vector2.
Camera.main.WorldToScreenPoint is a Vector3.
So your Vector3 - Vector2 is impossible. You can substract a Vector3 to another Vector3, or a Vector2 to another Vector2, but not mix them.
You can allocate a new Vector2 taking the Camera.main.WorldToScreenPoint x and y, and then substract your vectors.
Here I found a code that shakes the camera: https://gist.github.com/ftvs/5822103
But how to use it if I want to shake the camera only when a bullet hits something?
In the link you posted there are:
// How long the object should shake for.
public float shake = 0f;
If the shake variable is set to for example 1 the camera will shake as long as it is greater than one. The code is decreasing the value so that the number you set is equivalent to seconds you want the shake to last.
Then how to shake when bullet hits something? You can add code to the bullet that starts the shaking. This can be done in the collision of the bullet. Use something like this:
public class BulletScript : MonoBehaviour {
void OnCollisionEnter2D(Collision2D coll) {
GameObject.Find("Main Camera").GetComponent<CameraShake>().shake = 0.25f;
}
}
For this to work you need the bullet and the counter part to have 2D colliders.
PS. Find is really slow operation, so you might want to optimize the code by setting pointer to CameraShake into static variable only once in a scene.
I am trying to use the example from here with code here, about custom animations into a GridView.
All is working OK until I try to use a BitmapDrawable instead of a ColorDrawable.
mBackground = getResources().getDrawable(R.drawable.activity_background);
topView.setBackgroundDrawable(mBackground);
If using a BitmapDrawable, when swiping from main activity to the PictureDetailsActivity and back, makes the background from the main activity disappear. In logs I keep seeing this error when the background is gone (sometimes background is gone only when swiping the list, with the same error below):
Method getAlpha() with type int not found on target class
class android.graphics.drawable.BitmapDrawable
Searching the error I cannot find anything about it.
EDIT:
I am using alpha for fading in and out the background, as in the example:
// Fade in the background
ObjectAnimator bgAnim = ObjectAnimator.ofInt(mBackground, "alpha", 0, 255);
bgAnim.setDuration(duration * 2);
bgAnim.start();
and
// Fade out background
ObjectAnimator bgAnim = ObjectAnimator.ofInt(mBackground, "alpha", 0);
bgAnim.setDuration(duration * 2);
bgAnim.start();
You are probably testing on a device/emulator which is < API19, while getAlpha() was only added on API19. Hence,
Method getAlpha() with type int not found
Please make sure to test on a target with minimum Android 4.4 (KitKat) installed.
I have an app which uses the Tween method for a number of animations. One of the tweens is the following:
pipe_Tweener.Tween(3.2f,
FLOAT, &pSprite->m_X, (float) -pSprite->GetImage()->GetWidth(),
FLOAT, &pSprite->m_Y, (float) pSprite->m_Y,
FLOAT, &pSprite->m_X, (float) -pSprite->GetImage()->GetWidth(),
FLOAT, &pSprite->m_Y, (float) pSprite->m_Y,
ONCOMPLETE, &Game::ResetP,
END);
and another is:
pipe_Tweener.Tween(JUMP_TIME,
FLOAT, &bSprite->m_X, (float) bSprite->m_X,
FLOAT, &bSprite->m_Y, (float) bSprite->m_Y-JUMP_HEIGHT,
EASING, Ease::sineOut,
ONCOMPLETE, &Game::EndAnimating,
END);
These tweens seem to work fine when debugging using the x86 debug. However when I use the GCC ARM debug I end up with an IwAssert failure at line 360 in IwTween.cpp.
I've debugged through the Tween method, and what I've noticed is that for my first tween everything is fine, I can see the method going through each Type (FLOAT, FLOAT, FLOAT, FLOAT , ONCOMPLETE, END). However for the second tween when the Tween method gets to the END enum, Type becomes 0, (so I see for Type (FLOAT, FLOAT, EASING, ONCOMPLETE, 0) causing the default case statement to execute, which calls the assert failure.
I'm not sure if I'm doing something wrong or if this is a bug with Marmalade itself?
I've actually solved this, but I'll post in case it'll help anyone else.
My EndAnimating method was not static, which was causing some problem in the Tween method. Strangely it only caused a problem when debugging with the ARM simulator.