I am building a game in which i need to add a common topLayer as a common menu to other Layers. I am using AndEngineCocos2dExtension.
Current code :
public class LobbyLayer extends CCLayer {
CPButton low, medium, high, friends, vip;
CCSprite low_selected, medium_selected, high_selected, friends_selected,
vip_selected;
CCNode tables[];
public LobbyLayer() throws IOException {
CCSprite background = new CCSprite("gfx/bg.jpg");
background.setPosition(400, 240);
attachChild(background);
CPTopLayer topLayer = new CPTopLayer();
topLayer.setPosition(0,240);
attachChild(topLayer);
This is my second layer , I have a welcomeLayer ,which has a button for this(LobbyLayer), topLayer is the layer which i want on the top of the lobbyLayer.
But Instead I get a black Screen on the emulator, it is working fine without the topLayer.Please Help.
I'm not sure what branch you're on but GLES2 doesn't use layers anymore. When I searched andengine.org/forums for Cocos2dExtension, this is what I found:
http://www.andengine.org/forums/tools/porting-to-ios-t8450.html
I believe the cocos2d extension is so we can use cocos builder to build menu's and stuff so we have a graphical interface.
Does this help you?
You can specify the z value for the layers. I have used while adding child layer in parent layer as :
addChild(background,1);//z value 0
addChild(topLayer,5);//z value 5 so appear above background layer
Related
I am developing an application on Unity for Android Mobile platform. In which I am rotating object with single finger touch gesture, with the help of this script,
using UnityEngine;
public class MouseDragRotate : MonoBehaviour {
float rotationSpeed = 0.02f;
void OnMouseDrag()
{
float XaxisRotation = Input.GetAxis("Mouse X")*rotationSpeed;
float YaxisRotation = Input.GetAxis("Mouse Y")*rotationSpeed;
// select the axis by which you want to rotate the GameObject
transform.RotateAround (Vector3.down, XaxisRotation);
transform.RotateAround (Vector3.right, YaxisRotation);
}
}
But the problem is that, this script is working only on all Unity Assets for example cube, sphere, capsule and others. But not working with third party 3d objects,
So simply the question is why this script is not working on third party 3d objects ?
You have to have some sort of a Collider attached to the 3d-model/Object you would like to interact with. What you can do is add a BoxCollider to any Imported Object, or if there is a MeshFilter attached you could also add a MeshCollider.
You should make sure the script you show is added to the right top level object and not in a nested component of that object.
If you are still having problems please show us more about the objects you are trying to apply this to. And what components and option are set to it.
I want to create a map from some opengl code that I wrote :
In order to do that I though about taking a screen shot of the upperview of the gl screen.
Yet I cant seem to find how to do that...
any suggestions?
Similar problem has been solved in OSG example code here.
First you need to set your view such that you are looking at center from the TOP VIEW.
osg::Vec3 center = scene->getBound().center();
double radius = scene->getBound().radius();
view->getCamera()->setViewMatrixAsLookAt( center - lookDir*(radius*3.0), center, up );
view->getCamera()->setProjectionMatrixAsPerspective(
30.0f, static_cast<double>(width)/static_cast<double>(height), 1.0f, 10000.0f );
Then, you need to use some OS specific API to do similar to logic below:
osgViewer::ScreenCaptureHandler* scrn = new osgViewer::ScreenCaptureHandler();
osgViewer::ScreenCaptureHandler::WriteToFile* captureOper = new osgViewer::ScreenCaptureHandler::WriteToFile(tmpStr.m_szBuffer, "png");
scrn->setCaptureOperation(captureOper);
scrn->captureNextFrame(*_viewer);
_viewer->frame();
Of course if you are not using OSG then you need to find equivalent APIs (of library you are using) to achieve the same task.
I have an interesting problem with displaying two or quads at the same time while displaying one is working fine.
I was able to implement this popular tutorial for displaying a simple quad with texture:
http://www.jayway.com/2010/02/15/opengl-es-tutorial-for-android-part-v/
So basically i have a class named SimplePlane that extends Mesh class exactly as in tutorial.
I create an instance of SimplePlane:
public void onSurfaceCreated(...){
plane1 = new SimplePane(1,1);
plane2 = new SimplePane(1,1);
plane1.z = 2.0f
plane2.z = 3.0f
}
and then I draw mesh:
public void draw(GL10 gl) {
//set all gl variables as usual for opengl
plane1.draw(gl); // is displayed properly
plane2.draw(gl); //for some reason is not visible even that its behind plane1 and bigger to make sure plane1 is not covering plane2
}
The problem is only the first plane1 is being displayed.
If in my code i place plane2 first then plane 2 is diplayed and plane1 is not.
Mind you its not the z position issue as i ruled it out by creating one larger and semi transparent. And if i comment one out then the other is visible.
I added logging and both plane's draw methods are being called but only one is visible.
Am I allowed to take this approach calling one draw(gl) after another or i have to create a group object as in tutorial?
I'm developping a game which implements gif sprites...
After start with gif I used png image and for change the TextureRegion of my sprite I followed this guide: Sprite.setImage() in andengine and it worked very well.
Now I want to do the same thing with AnimatedSprite. Can someone tell me How i can edit the org.anddev.andengine.entity.sprite.AnimatedSprite.java to create:
sprite.setAnimatedTextureRegion(PixelPerfectTiledTextureRegion textureRegion)
P.S I use also PixelPerfect
The AnimatedSprite class uses the same texture region declared in BaseSprite, so the code in the link you gave will work - just paste it in the AnimatedSprite.java file:
public void setTiledTextureRegion(TiledTextureRegion textureRegion) {
this.mTextureRegion = textureRegion;
}
Note: If the different tiled textures have different number of tiles (So each has a different animation parameters associated with it) you should handle it in your code. It may get complicated, so I'd just create a new AnimatedSprite instead of replacing the texture region.
I have a view which can contain multiple sprites at a time, now i want to have a select effect when ever i touch a sprite.
Some Usefull/helping links would be very helpfull.
I see two ways:
To change the sprite with selected version (make original sprite invisible and show selected).
Create a frame sprite (possibly from multiple parts (add them to one parent)) and show it when you need to select the original sprite.
SOME CODE
CCNode *base = [CCNode node];
CCSprite *original = [CCSprite node]; //change this to create your sprite
[base addChild:original]
CCNode *frameNode = [CCNode node];
[base addChild: frameNode];
[frameNode setVisible:NO];
CCSprite *part1 = [CCSprite node]; //replace to create your part
[frameNode addChild: part1];
[part1 setAnchorPoint:. ...];
[part1 setPosition: ...];
[part1 setRotation: ...];
//add more parts
When your original sprite is selected:
[frameNode setVisible: YES]; //you can also use some CCAction to make it appear more beautiful