Here is my code which works fine
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BLACKWHITE);
mEffect.setParameter("black", .9f);
mEffect.setParameter("white", .5f);
break;
but now I want two effects on it, what to do ?
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_BLACKWHITE);
mEffect.setParameter("brightness", 2.0f);
I want to marge both effects with "grayscale image"
mEffect = effectFactory.createEffect(EffectFactory.EFFECT_GRAYSCALE);
I also look at this documents but no help [GLSurfaceView][1]
1: https://developer.android.com/reference/android/opengl/GLSurfaceView.html ,
EGLDisplay
1: https://developer.android.com/reference/android/opengl/EGLDisplay.html and Effect factory too
Related
The title says it all.
switch (colorChosen) {
case "Red":
setEverythingColors(255,0,0,colorChosen);
case "Brown":
setEverythingColors(165,42,42,colorChosen);
case "Orange":
setEverythingColors(255,165,0,colorChosen);
case "Blue":
setEverythingColors(0,0,255,colorChosen);
case "Green":
setEverythingColors(0,128,0,colorChosen);
case "Purple":
setEverythingColors(128,0,128,colorChosen);
case "Pink":
setEverythingColors(246,171,205,colorChosen);
case "Yellow":
setEverythingColors(255,255,0,colorChosen);
case "Grey":
setEverythingColors(128,128,128,colorChosen);
}
and the setEverythingColors method is this
public void setEverythingColors(int c1, int c2, int c3, String color){
backgroundColor.setBackgroundColor(Color.rgb(c1,c2,c3));
colorTitle.setText(color);
}
For some reason the build is successful and i get no errors or warnings but whichever the case, the color is never being set and i'm pulling my hair over here!
What might be the case??
switch-case can work String if it is constant, your code has working but you forget break, and default. You can retry:
switch (colorChosen) {
case "Red":
setEverythingColors(255, 0, 0, colorChosen);
break;
case "Brown":
setEverythingColors(165, 42, 42, colorChosen);
break;
case "Orange":
setEverythingColors(255, 165, 0, colorChosen);
break;
case "Blue":
setEverythingColors(0, 0, 255, colorChosen);
break;
case "Green":
setEverythingColors(0, 128, 0, colorChosen);
break;
case "Purple":
setEverythingColors(128, 0, 128, colorChosen);
break;
case "Pink":
setEverythingColors(246, 171, 205, colorChosen);
break;
case "Yellow":
setEverythingColors(255, 255, 0, colorChosen);
break;
case "Grey":
setEverythingColors(128, 128, 128, colorChosen);
break;
default:
break;
}
I found what was wrong.
case "Red":
case "Brown":
etc..
was the problem. I was referring to the string in the same way as i would refer to integers.
I can't say colorChosen=="Red" because it is a string.
I changed my switch statement to if statements and used colorChose.equals("Red") instead and that solved the problem.
I have 3 Translate Animation to be played when the app starts -
Animation animation = new TranslateAnimation(0, 0, -1500, 1500);
animation.setDuration(1000);
animation.setFillAfter(false);
myimage.startAnimation(animation);
animation.setRepeatCount(Animation.INFINITE);
Animation animation2 = new TranslateAnimation(0, 0, -1000, 1000);
animation2.setDuration(1000);
animation2.setFillAfter(false);
myimage2.startAnimation(animation2);
animation2.setRepeatCount(Animation.INFINITE);
Animation animation3 = new TranslateAnimation(0, 0, -500, 500);
animation3.setDuration(1000);
animation3.setFillAfter(false);
myimage3.startAnimation(animation3);
animation3.setRepeatCount(Animation.INFINITE);
I want to start the above 3 in random order, not necessarily the first one first.
One full day gone and I'm still unable to find a solution.
Any pointers on how to achieve it ?
You can generate random number in java and do switch
Random random = new Random();
int num = 3;
switch(random.nextInt(num)) {
case 0:
animateFirst();
break;
case 1:
animateSecond();
break;
case 2:
animateThird();
break;
}
This is one way I got, modifying your code, #Murtaza Hussain
switch(random.nextInt(num)) {
case 0:
animateFirst();
animateSecond();
animateThird();
break;
case 1:
animateSecond();
animateFirst();
animateThird();
break;
case 2:
animateFirst();
animateThird();
animateSecond();
break;
}
I am attempting to make a slider bar that randomly changes the color of several parts of the users interface when the user slides the bar from one side to the other. I have a piece of code that already works but I know it's not as efficient as it could be. I have 3 of the same layout modifiers as below:
private void getLayout2(){
int color = 0;
final Random randColor2 = new Random();
int control = randColor2.nextInt(4);
switch(control){
case 0: color = getResources().getColor(R.color.White);
Log.i(TAG, "color is white");
break;
case 1: color = getResources().getColor(R.color.Red);
Log.i(TAG, "color is red");
break;
case 2: color = getResources().getColor(R.color.Yellow);
Log.i(TAG, "color is yellow");
break;
case 3: color = getResources().getColor(R.color.Blue);
Log.i(TAG, "color is blue");
break;
}
Layout2.setBackgroundColor(color);
return;
}
What I would like to do is change all of the layout backgrounds in the same piece of code but I am not sure how to do that as there is only one color variable and I don't want all the colors to be the same at any given time. Currently I am just calling multiple versions of this method for each layout in the "onProgressChanged" method of the slider listener. Can this be done in a single method with this scheme?
There are a number of options. You can have your function return a the color and set it your main routine, or you can pass the layout as a parameter to your function. An example of the latter follows. Since this is a function, the color variable is recreated every time it is called, so no need to worry that it will be the same when you call the function a different time. Try it and see.
private void setRandomBackgroundColor(View layout){
int color = 0;
final Random randColor = new Random();
int control = randColor.nextInt(4);
switch(control) {
case 0:
color = getResources().getColor(R.color.White);
Log.i(TAG, "color is white");
break;
case 1:
color = getResources().getColor(R.color.Red);
Log.i(TAG, "color is red");
break;
case 2:
color = getResources().getColor(R.color.Yellow);
Log.i(TAG, "color is yellow");
break;
case 3:
color = getResources().getColor(R.color.Blue);
Log.i(TAG, "color is blue");
break;
}
layout.setBackgroundColor(color);
return;
}
I currently have a body created that is Dynamic and moves at a constant speed with a Vector2(). What I want is for when the body leaves the edge of the screen, to come back from that current point back to its original point instantaneously. How do I do this?
a.applyForceToCenter(aMovement, true);
a.applyTorque(3000, true);
FixtureDef fDef = new FixtureDef();
BodyDef ballD = new BodyDef();
ballD.type = BodyType.DynamicBody;
//random location for asteroid
int aLoc = (int) (aLocation * 15);
float x = 300;
switch(aLoc)
{
case 0:
ballD.position.set(x, -105);
break;
case 1:
ballD.position.set(x, -95);
break;
case 2:
ballD.position.set(x, -80);
break;
case 3:
ballD.position.set(x, -65);
break;
case 4:
ballD.position.set(x, -50);
break;
case 5:
ballD.position.set(x, -35);
break;
case 6:
ballD.position.set(x, -20);
break;
case 7:
ballD.position.set(x, -5);
break;
case 8:
ballD.position.set(x, 10);
break;
case 9:
ballD.position.set(x, 25);
break;
case 10:
ballD.position.set(x, 40);
break;
case 11:
ballD.position.set(x, 55);
break;
case 12:
ballD.position.set(x, 70);
break;
case 13:
ballD.position.set(x, 85);
break;
default:
ballD.position.set(x, 0);
}
PolygonShape asteroid = new PolygonShape();
asteroid.setAsBox(12.5f, 12.5f);
//asteroid definition
fDef.shape = asteroid;
fDef.density = .5f;
fDef.friction = .25f;
fDef.restitution = .75f;
a = world.createBody(ballD);
a.createFixture(fDef);
a.setFixedRotation(false);
//asteroid image
aSprite = new Sprite(new Texture("img/asteroid-icon.png"));
aSprite.setSize(12.5f * 4, 12.5f * 4);
aSprite.setOrigin(aSprite.getWidth() / 2, aSprite.getHeight() / 2);
a.setUserData(aSprite);
asteroid.dispose();
You could use Body.setTransform() for that task, but I would not do that. setTransform() causes a lot of trouble in the long run.
For me it lead to weird bugs. For example using setTransform disabled my ContactFilter in random moments, which cost me several days of debugging until I found that.
Furthermore it causes non-physical behaviour, because you basically teleport the Body.
Better would be to destroy the Body completely and recreate a new one at the same initial position of the old one.
You can set the position of your Box2D a body instantly through this method:
a.setTransform(new_x, new_y, new_angle);
With this, you can create a condition that sets the x and y position of the body back to its original position when the x or y value of the body is outside of the screen.
if(outsideBounds()){
a.setTransform(start_x, start_y, start_angle);
}
You can check whether your object is offscreen by either checking its Box2D position and its converted screen coordinates, or by checking the sprite's location.
Once you've received the x and y screen positions, you can compare them to the screen bounds like this:
pos_x>screenWidth||pos_x<0||pos_y>screenHeight||pos_y<0
This can be improved by including the dimensions of the object, depending on when you want the transformation to happen:
(pos_x-objWidth)>screenWidth || (pos_x+objWidth)<0 ||
(pos_y-objHeight)>screenHeight || (pos_y+objHeight)<0
You can use the following:
body.setTransform(newX, newY, newAngle);
body.setAwake(true);
Waking up the body is important.
It might be currently inactive and without waking it up neither gravity nor any immediate collisions will affect it at the new position.
I'm developing application, where activity starts after phone's rotation. When you rotate phone backward that activity have to finish. Is it possible to ignore rotation around other axes?
You can check which way the phone is held with this:
Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int rotation = display.getRotation();
Then you can check the orientation like this:
switch (rotation)
{
case Surface.ROTATION_90:
...
break;
case Surface.ROTATION_180:
...
break;
case Surface.ROTATION_270:
...
break;
default:
...
break;
}
(Note that for pre-API 8 versions you'd need to use display.getOrientation() instead of display.getRotation())