I am facing an strange issue not sure why this is happening.
I have a Java based Activity which has a LinearLayout. This LinearLayout consists of two GLSurfaceView. All the associated methods of GLSurfaceView like OnDraw, SurfaceChanged etc are moving call down to JNI layer. Inside the JNI layer I am drawing a cube using OpenGLES. I have also created a touch listener and have associated it with first GLSurfaceView. Once I get a touch event I move the call to JNI layer and randomly rotate the first cube.
Problem is when I rotate my first cube both the cubes rotates at exactly same angle. I have debugged this issue for last four hours and I am pretty sure there is nothing wrong in my logic. But for some unknown reason when I make change in one GLSurfaceView other cube changes automatically.
Any ideas? Similar issues? Guess?
Update
I am using same context i.e. my activity for both GLSurfaceView. Basically I have a class inside C++ which draws cube through opengles. Now I am successfully creating two cubes and displaying them simultaneously. Both cubes have different texture on them which I am passing via Java layer. My c++ class has a method which randomly rotates the cube. Problem is if I call method of one cube to rotate it other automatically rotates at same angle no make what I do.
Without your code, I'd guess you are initializing your GLSurfaceView's using the same context. When sharing a context changing one will change the other because they will share the same GL10 instance in the Renderer. I don't program in android, but in general you'd use multiple "viewports" to display different things.
Say that your first GLSurfaceView is on the first left side of your screen, and the second is on the second right half. One idea is to check what side the coordinates x, y of the motionEvent belongs to. And then pass rotation and translation accordingly.
Issue solved there was one logical mistake in my code
Sorry for inconvenience
Related
i have been searching for hours, and cant seem to find an answer
i have a chess board and its made of 64 imageViews (8X8) and i want to move one pawn to another square, and cant seem to find the way to get the image resource (which is a png image) and set it on the empty square. i saw answers to this question using .setTag, but i am already using it to define the position of the imageView on the board (for example the tag could be "4,4")
a part of my code below:
it shows the imageView and how im setting the resource.
i have another image view and i want to get the resource from the first one and onto the other one
img.setBackgroundResource(R.drawable.white_pawn_on_beige);
thanks in advance.
If you think you need to do this, you're architecting your program incorrectly. You should have a model that knows what every square on the board has as a piece (if any). You should also have a function that can map a piece (or lack of a piece) to a resource id. You should simply update that model when a move is made, then redraw any effected squares from the model. You should not be using your views as state. Moving to an architecture like this should both make it easier to write and to test (instead of a complicated test involving views, you're testing a function that updates the model, a function that maps the model to a resource for a given square, and a function that updates a model- no views involved).
on a 100x50 orthogonal tilegrid with 32x32 tiles, i created some animated Units, which are moved by A* (like in many strategy games usual) with a rightclick on the mouse.
The collision detection works by using a two dimensional booleanarray i gave the grid in the constructor and this says whether a tile is an obstacle or not.
Thats what i have so far and it works.
I am now figuring out, some Kind of Units coordinationsystem, which simply doesnt allows the Units to walk into each other. All of this just should be in this 32x32 tilesized RASTER not more for the moment.
I just thought this should be easy, but the grid is loaded once just like the obstacles, while the Units positions are always different and the Problem here is, that if i define each unit as an obstacle at Runtime, the obstacle at its Position stays stored in the gridarray and it stay some Kind of invisible obstacle, although it shouldnt be one. The result is, that the unit cant go the way back, where it cames from. Another Problem is of Course, that a unit can stand still or move arround(so far) and if it moves arround ist not rastered anymore.
My question now is: How can i implement a movable obstacle or do i have to implement a separate collision detection for my Units here?
PS: The Programm is quite big and i dont like to post the whole Code, although that would make all easier for u guys to help me, but if somebody understand what i mean, i can post the relevant Code snippets here on the Forum.
I'm making a libgdx game where the user can create a distance joint and a revolute joint on its own, so what I do whenever 2 bodies have been touched they are both added to an arrayList, then when a button is touched a joint will be created. The problem is that the joint are always at the center, so I was wondering if there is a way to get the location of the body where it was touched?, then set those locations as anchorPointA and anchorPointB.
The first idea I get is a Gesture listener, see for example the GestureDetector.GestureAdapter(). Then you implement the touchDown method where you can get the x, y touch positions. To see wheter a body is touched, you might use the Vector.dst() method, but don't forget to unproject if you need.
Another idea might be to add an InputListener to your actor (which is connected to your body), but I haven't tried it yet.
Background:
I am making a 2D side-scroller.
When the player touches the screen, the player moves forward (the camera follows the player).
I cannot find an answer to this question although it seems rather straightforward.
Question:
How can I get my parallax background to scroll only when my player moves?
(example code would make things much easier for me)
I am using autoparallaxbackground but it seems that it simply just scrolls at the rates you pass in, with no regard to the camera. Moreover, I am not fully sure of the difference between autoparallaxbackground and parallaxbackground.
Any help is appreciated!
AutoParallaxBackground extends ParallaxBackground, adding one simple feature: automatically changing mParallaxValue with time. As you may imagine, if you don't need your background constantly moving, you may use ParallaxBackground as your base class, and then use setParallaxValue(final float pParallaxValue) to manually adjust the position.
In my little game, I have a background and a player, and obstacles to prevent the player from gaining points. So the player needs to move to avid these obstacles, right? Well my method of taking touch input works and when the user touches the right/left side of the screen to move in the corresponding direction. For some reason my method requires the user to tap the screen once for every single movement (4 pixels) of the player. I want the user to be able to hold their finger down on the direction they wish to go, and not have to continually tap that side of the screen a few hundred times. I'm pretty new to android, so I don't really know how to implement this. I have tried a game loop (it just crashed my game), and I've tried a separate thread to try and repeat the action, but it never gets executed even after I call "game.run()" and with "game.start()" it crashes. Can anyone show me a simple way to make it to where me player will keep moving when holding your finger on the side you wish to move towards? I imagine it's simple and I'm over complicating it, but I am a little clueless. Please provide an example, and not just a "Do it like that" etc. Because again, I am a little clueless in this department. Code pastebin'd below.
My code: http://pastebin.com/3EetUHCx
You want to create a new Runnable object in which to put the code, not to implement Runnable in the main class. That way you will separate the event handling from the main UI.
Even a better option would be to extend SurfaceView instead of View in your Draw class and create a Tread object inside that SurfaceView to handle the actual drawing.
Take a look at the Lunar Lander example from the android dev guide.