LayoutGameActivity - mixing AndEngine with other Views!

  ... information about changes and new features of AndEngine,

LayoutGameActivity - mixing AndEngine with other Views!

Postby Nicolas Gramlich » Sun Oct 10, 2010 7:15 pm

Hello Community,

some days ago I added a new example: XMLLayoutExample, which is using the new LayoutGameActivity class that makes integration of an AndEngine view into an complex layout trivial (Note, placing it into a ScrollView is not supported due to how SurfaceViews work :!: Looks funny though :D ) .

This is pretty much what needs to be added, compared to the usual BaseGameActivity:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         protected int getLayoutID() {
  3.                 return R.layout.xmllayoutexample;
  4.         }
  5.  
  6.         @Override
  7.         protected int getRenderSurfaceViewID() {
  8.                 return R.id.xmllayoutexample_rendersurfaceview;
  9.         }
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


This is what the example looks like on my Nexus:
device.png
device.png (33.33 KiB) Viewed 10054 times


Please keep in mind that this new 'feature' is pretty young and might be subject to changes :!:

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby vael » Mon Oct 11, 2010 9:25 pm

Hello Nicolas,

I've got a problem about ratio. Before making custom view through xml this worked fine:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2. @Override
  3.         public Engine onLoadEngine()
  4.         {                      
  5.         DisplayMetrics displayMetrics = new DisplayMetrics();
  6.         this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
  7.        
  8.         int CAMERA_WIDTH = displayMetrics.widthPixels;
  9.         int CAMERA_HEIGHT = displayMetrics.heightPixels;
  10.        
  11.                 this.TheCamera = new ZoomCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
  12.                 this.TheCamera.setZoomFactor(CAMERA_HEIGHT / Activity_Gameplay.GAME_HEIGHT);
  13.  
  14.         Activity_Gameplay.GAME_WIDTH = CAMERA_WIDTH / this.TheCamera.getZoomFactor();
  15.                
  16.                 this.TheCamera.setCenter(Activity_Gameplay.GAME_WIDTH / 2.0f, Activity_Gameplay.GAME_HEIGHT / 2.0f);
  17.                
  18.                 this.VisualEngine = new Engine(new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.TheCamera));
  19.                
  20.                 return this.VisualEngine;
  21.         }
  22.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


But now when ad appears on the top displayMetrics.heightPixels won't return the actual view height. And I will obviously get a black bar. How to solve this?

Thank you
vael
 
Posts: 12
Joined: Fri Sep 10, 2010 6:43 am

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby Nicolas Gramlich » Tue Oct 12, 2010 12:36 am

Hi,

displayMetrics return the actual size of the whole physical display and not the size of the View :!:

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby vael » Tue Oct 12, 2010 11:53 am

I understand that but how can I get the view size at this moment if onSetContentView() is called after onLoadEngine()?
vael
 
Posts: 12
Joined: Fri Sep 10, 2010 6:43 am

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby vael » Tue Oct 12, 2010 12:03 pm

And also how to catch the moment when the view size changes (ad appears or disappears) and change camera/engine the right way?
vael
 
Posts: 12
Joined: Fri Sep 10, 2010 6:43 am

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby Knossos » Tue Oct 12, 2010 4:06 pm

Very impressive.

Works perfectly.
Portal Origin Systems
Website/Software Design and Development company
http://www.portalorigin.com
Knossos
 
Posts: 20
Joined: Thu Aug 12, 2010 11:00 am
Location: Koblenz, Germany

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby vael » Sat Oct 16, 2010 3:33 pm

So does anyone know the answer to my previous question?

Thanks
vael
 
Posts: 12
Joined: Fri Sep 10, 2010 6:43 am

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby ndiiie90 » Sat Feb 12, 2011 6:34 am

Hey Nicholas!

Thx for this tutorial! finally the ads can be added to my game! :)

But, I have a question, can't just the ads overlap the game? just like in angry birds..

Thx
ndiiie90
 
Posts: 28
Joined: Tue Feb 01, 2011 7:50 pm

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby Nicolas Gramlich » Sun Feb 13, 2011 7:03 pm

vael wrote:So does anyone know the answer to my previous question?


Not really, currently the size cannot be changed afterwards. I simply place the ads above the screen.

ndiiie90 wrote:But, I have a question, can't just the ads overlap the game? just like in angry birds..


Yes, in FarmTower I do it just like Angry Birds does it. Display ads the first ~5 seconds of the game.

Best Regards,
Nicolas
Nicolas Gramlich
Site Admin
 
Posts: 1734
Joined: Mon Jun 07, 2010 6:20 pm
Location: Schriesheim, Germany

Re: LayoutGameActivity - mixing AndEngine with other Views!

Postby ndiiie90 » Sat Feb 19, 2011 12:43 pm

Nicolas Gramlich wrote:
vael wrote:
ndiiie90 wrote:But, I have a question, can't just the ads overlap the game? just like in angry birds..


Yes, in FarmTower I do it just like Angry Birds does it. Display ads the first ~5 seconds of the game.

Best Regards,
Nicolas



How can you do that?
I just follow your tutorial above and customize my xml like this:

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <LinearLayout
  3.         xmlns:android="http://schemas.android.com/apk/res/android"
  4.        android:layout_width="fill_parent"
  5.        android:layout_height="fill_parent"
  6.        android:orientation="vertical"
  7.        android:gravity="center">
  8.  
  9.         <com.admob.android.ads.AdView
  10.         android:id="@+id/ad"
  11.         android:layout_width="fill_parent"
  12.         android:layout_height="60px"
  13.         android:gravity="center"
  14.         android:layout_alignParentTop="true"
  15.         myapp:backgroundColor="#FFFFFF"
  16.         myapp:primaryTextColor="#000000"
  17.         myapp:secondaryTextColor="#CCCCCC"
  18.         />
  19.  
  20.          <org.anddev.andengine.opengl.view.RenderSurfaceView
  21.                 android:id="@+id/xmllayoutexample_rendersurfaceview"
  22.                 android:layout_width="fill_parent"
  23.                 android:layout_height="fill_parent"
  24.                 android:gravity="center"
  25.           />
  26.  
  27. </LinearLayout>
  28.  
Parsed in 0.003 seconds, using GeSHi 1.0.8.4


It has some different codes with your example..And the result is the game only takes place 3/4 screen size and remains blank space in top, right and bottom side of game (right side is for ads)..Am I miss something Nicolas so that the ads can overlap my game and the game takes place whole screen?

Thanks a lot NIcolas..
ndiiie90
 
Posts: 28
Joined: Tue Feb 01, 2011 7:50 pm

Next

Return to Updates

Who is online

Users browsing this forum: No registered users and 5 guests