Showing posts with label Android Studio. Show all posts
Showing posts with label Android Studio. Show all posts

Sunday, 10 February 2019

5/2/2019 - Static fragment and dynamic fragment



Static fragment

  • Static fragment is a fragment that can't be change during runtime.
  • It uses <fragment> widget from Android Studio.
  • Only .xml file.
  • Nothing need to be declared in MainActivity.java



Dynamic fragment

  • Dynamic fragment is a fragment that can be change during runtime.
  • It uses FrameLayout widget to be a container for it.
  • It needed to be declare in the MainActivity.java

For example,

Dynamic fragment sample code:

//MainActivity.java
public class MainActivity extends AppCompatActivity
{
   //set as public static, so it can be use in other fragment activity too
   public static FragmentManager frag_manager;

   @Override
   protected void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      frag_manager = getSupportFragmentManager;
      
      //the FrameLayout id = fragContainer in activity_main.xml
      if (findViewById(R.id.fragContainer) != null)
      {
         //if the item is saved, which means that there is already a item there
         if (savedInstanceState != null)
         {
            return;
         }
         
         //begin the transaction for fragment
         FragmentTransaction frag_trans = frag_manager.beginTransaction();

         //declare the first fragment item, which is the FirstFrag.java
         FirstFrag first_frag = new FirstFrag();

         //add the first_frag.xml to the FrameLayout container
         frag_trans.add(R.id.fragContainer,first_frag,false);

         //commit the fragment
         frag_trans.commit();
      }
   }

}


The code above will add the fragment into a FrameLayout container. The fragment inside the container can be change, eg. currently is first_frag.xml in FirstFrag.java, but it can be chage to second.frag.xml in SecondFrag.java too, a button can be add to perform the change of fragement during runtime.







Tuesday, 5 February 2019

4/2/2019 - Learning Android Studio






Saturday, 2 February 2019

1/2/2018 - Learning Android studio for the colorman dodge game




  • Problem face: need to generate random amount of hailstones to fall from the sky, and need to find an algorithm to make sure that when the hailstone hit colorman, the game will end.
  • Maybe will have to create another simple game to test the algorithm.
  • Learning some basics from Retro Chicken.

Wednesday, 30 January 2019

30/1/2018 - Colorman dodge (Basic codes)




These are some basic codes samples I think I would use it much in the future:
  • <activity android:screenOrientation = "sensorLandscape"> inside AndroidManifest.xml file to make sure that the gamescreen is in landscape mode.
  • private int screenWidth = Resources.getSystem().getDisplayMetrics().widthPixels; //get the screen height
  • private int screenHeight =Resources.getSystem().getDisplayMetrics().heightPixels; //get the screen height
  • private Bitmap image = BitmapFactory.decodeResource(getResources(),R.mipmap.ic_launcher); //get the image of ic_launcher in res/mipmap

  • In order to make the graphics work on any screen, every images is related to each other. For example, no matter what the screen size is, colorman will always walking on the ground, this is because I make the colorman sprite grow with background. If the background grow at the scale of 2, the colorman sprite will grow at the scale of 2 too.
  • Colorman moving left and right when user touches the left side of the screen, and the right side of the screen. (the upper left corner still have the original hailstone file)

29/1/2018 - Planning to create a simple dodging game




  • Planning to create a dodging game while there is some hailstones falling from the sky and the player will try and dodge it
  • A sprite is created


  • A background is created

  • Falling items are created

  • Made the background fit the screen size
  • Put everything into 1 screen

  • Problem: need to think of an algorithm that will make image everything dynamic



Tuesday, 29 January 2019

28/1/2019 - Learning Basic Android Studio for Game




  • Created a sample code Hypeman.apk, which will just shows hypeboy walking animation.


<>


Hypeman.apk has a frame-rate of approximately 1FPS. It will repeatedly loop the walking animation.

PS. Tested only in Samsung Galaxy Note 3. The problem with this is when user tilt the screen from portrait to landscape, the Hypeman will not be in the screen. This is because Hypeman wasn't created dynamically.



18/7/2019 - Survive that planning

Planning A top-down shooting game Player use WASD to move Use mouse cursor to aim Mouse left-click to shoot, and right click to throw ...