• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Game dev graphics

I'm wondering about working with graphics when developing games.

So far, my only work with graphics has been importing an image for a splash screen. There hasn't been a lot of positioning I've had to deal with - which is what I'm wondering about. How do you position images for a game?

Since you can't know the screen resolution, it seems that absolute positioning won't work. But constraint layout and relative layout don't seem like they would work for something like laying out tiles or moving an object around (i.e. Candy Crush and Breakout games). So is there a specific approach to doing this?

Reference to tutorials would also be welcome.

Thanks!

Bitmap not loading

I'm having a problem with a bitmap not loading after trying to change from a view to a background theme splash page.

For reference, I'm using the splash screen method given at https://www.bignerdranch.com/blog/splash-screens-the-right-way/

I must be missing something but I'm not seeing what.

Here are the relvant files:
styles.xml
Code:
<resources>

    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

    <style name="SplashTheme" parent="Theme.AppCompat.NoActionBar">
        <item name="android:windowBackground">@drawable/splash_screen</item>
    </style>

</resources>

Manifest (relevant parts):
Code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    package="com.poc.justamap">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">

        <activity android:name=".MainActivity" android:theme="@style/SplashTheme">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MapsActivity"
            android:label="@string/title_activity_maps">
        </activity>

    </application>

</manifest>

MainActivity:
Code:
public class MainActivity extends AppCompatActivity {

    private Handler mHandler = new Handler();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mHandler.postDelayed(new Runnable() {
            @Override
            public void run() {
                loadHomePage();
            }
        },5000);
    }

    private void loadHomePage() {
        Intent nextPage = new Intent(MainActivity.this, MapsActivity.class);
        MainActivity.this.startActivity(nextPage);
    }
}
(I'm delaying right now just so I can really see the splash screen)

It's failing on onCreate, saying the bitmap needs a valid src attribute. I've checked, ic_launcher is there, and I've verified that it's a valid image file. I WAS using it previously when I was just loading MainActivity and pausing for a second - that worked ok. It has only stopped working since I made this update.

Stack trace:
Code:
I/InstantRun: starting instant run server: is main process
D/skia: --- SkAndroidCodec::NewFromStream returned null
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.poc.justamap, PID: 6708
    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.poc.justamap/com.poc.justamap.MainActivity}: android.content.res.Resources$NotFoundException: Drawable com.poc.justamap:drawable/splash_screen with resource ID #0x7f06007d
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2817)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: android.content.res.Resources$NotFoundException: Drawable com.poc.justamap:drawable/splash_screen with resource ID #0x7f06007d
     Caused by: android.content.res.Resources$NotFoundException: File res/drawable/splash_screen.xml from drawable resource ID #0x7f06007d
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:768)
        at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:600)
        at android.content.res.Resources.getDrawableForDensity(Resources.java:876)
        at android.content.res.Resources.getDrawable(Resources.java:818)
        at android.content.Context.getDrawable(Context.java:605)
        at androidx.core.content.ContextCompat.getDrawable(ContextCompat.java:463)
        at androidx.appcompat.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:203)
        at androidx.appcompat.widget.TintTypedArray.getDrawableIfKnown(TintTypedArray.java:86)
        at androidx.appcompat.app.AppCompatDelegateImpl.<init>(AppCompatDelegateImpl.java:260)
        at androidx.appcompat.app.AppCompatDelegate.create(AppCompatDelegate.java:182)
        at androidx.appcompat.app.AppCompatActivity.getDelegate(AppCompatActivity.java:520)
        at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:71)
        at com.poc.justamap.MainActivity.onCreate(MainActivity.java:14)
        at android.app.Activity.performCreate(Activity.java:6975)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1213)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2770)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2892)
        at android.app.ActivityThread.-wrap11(Unknown Source:0)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1593)
        at android.os.Handler.dispatchMessage(Handler.java:105)
        at android.os.Looper.loop(Looper.java:164)
        at android.app.ActivityThread.main(ActivityThread.java:6541)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
     Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #8: <bitmap> requires a valid 'src' attribute
        at android.graphics.drawable.BitmapDrawable.updateStateFromTypedArray(BitmapDrawable.java:823)
        at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:754)
        at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
        at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
        at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:1284)
        at android.graphics.drawable.LayerDrawable.inflateLayers(LayerDrawable.java:279)
        at android.graphics.drawable.LayerDrawable.inflate(LayerDrawable.java:194)
        at android.graphics.drawable.DrawableInflater.inflateFromXmlForDensity(DrawableInflater.java:142)
        at android.graphics.drawable.Drawable.createFromXmlInnerForDensity(Drawable.java:1295)
        at android.graphics.drawable.Drawable.createFromXmlForDensity(Drawable.java:1254)
        at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:758)
           ... 24 more

Can anyone see what I'm doing wrong here?

consumeAsync Return Error Code 5

I am getting error code 5 which I believe is 'Developer Error'. The mDebugMessage in the BillingResult is Invalid Token. (I have checked the name and I am sure it is correct.)

I am calling consumeAsync("noadverts"); where "noadverts" is the name of my in app product.

When I check my purchases, it records the following:

Code:
{"orderId":"GPA.1111-1111-1111-1111",
"packageName":"myname.com.myname",
"productId":"noadverts",
"purchaseTime":1565188785096,
"purchaseState":0,
"purchaseToken":"edited for length",
"acknowledged":true}

Unusually, when I call:

Code:
int val1 = purchase.getPurchaseState();

then val1 is 1 and not 0 as it suggested in the purchase JSON.

I am using much of the TestDrive example, but without the BillingUpdatesListener.

Code:
public void consumeAsync(final String purchaseToken) {
   // If we've already scheduled to consume this token - no action is needed (this could happen
   // if you received the token when querying purchases inside onReceive() and later from
   // onActivityResult()
   if (mTokensToBeConsumed == null) {
       mTokensToBeConsumed = new HashSet<>();
   } else if (mTokensToBeConsumed.contains(purchaseToken)) {
       //Log.i(TAG, "Token was already scheduled to be consumed - skipping...");
       return;
   }
   mTokensToBeConsumed.add(purchaseToken);

   // Generating Consume Response listener
   final ConsumeResponseListener onConsumeListener = new ConsumeResponseListener() {
       @Override
       public void onConsumeResponse(BillingResult response, String purchaseToken) {
           @BillingClient.BillingResponseCode int responseCode = response.getResponseCode();

           // THIS IS WHERE I GET ERROR CODE 5
       }
   };

   // Creating a runnable from the request to use it inside our connection retry policy below
   Runnable consumeRequest = new Runnable() {
       @Override
       public void run() {
           // Consume the purchase async
           //mBillingClient.consumeAsync(purchaseToken, onConsumeListener);

           ConsumeParams consumeParams = ConsumeParams.newBuilder().setPurchaseToken(purchaseToken).build();
           // Consume the purchase async
           mBillingClient.consumeAsync(consumeParams, onConsumeListener);
       }
   };

   executeServiceRequest(consumeRequest);
}

Any ideas what might be the issue?

If I try and purchase "noadverts" again I get the error code Item is already owned.

Help Google News keeps reactivating itself

Since I don't use Google News I want to disable it but the app doesn't want to stay disabled. This started happening after I cleared the cacahe and data of Google Play and Google Play Services to get rid of the download pending bug. I tried pretty much every trick I could find on the internet but it doesn't work. Luckily I'm not the only one with this problem but no one knows the solution so I'm posting this on every Android forum in hopes of finding a solution.

Device: Nokia 8.1
OS: Android 9 with July 2019 security patch.

S Pen Motion Controls

Samsung just announced that they're opening up S-Pen motion controls to 3rd party developers. That means popular apps and games could integrate interesting types of S Pen functionality. They gave some including YouTube which will let you adjust volume among other things without ever touching the screen.

Screen Shot 2019-08-07 at 4.22.34 PM.png


Pretty cool... but I wonder how many big apps/games will leverage the new SDK for S Pen Motion Controls. Very cool but not a must-have IMO.

Screen Shot 2019-08-07 at 4.22.18 PM.png

That metal key thing

Hi, I just got the S-10+ and liking it so far.

This may be the first of several questions that show my inexperience with these devices.

With the packaging, there is a metal key thing with a probe. I read this might be for accessing maybe the micro-SD card slot? There was nothing in the "Whats in the box" minimal literature on this metal key nor is there anything that tells me where to access and install a micro-SD

Are there any instructions or a manual...especially a searchable manual available for the S-10+? The Samsung site seems more intent on being flashy and cool and less on just giving me detailed info, down to the basics for me to get right to. Their chat has been somewhat helpful so far. A web search didn't answer my question easily on this specific phone.

I'm brand new with the S-10+ so I probably seem clueless. I jumped from an S5 I never really pushed the limits on either.

Custom Notification - Paddings

Hi,

I created a custom notification. However, I like to use the same padding for left- and right-padding that is used for standard notifications. I noticed that this padding can be different depending on the device.

I found the followinf notification style that applies the correct left-right-padding, but it also adds additional stuff that I do not like. Example for the style:

NotificationCompat.Style style = new NotificationCompat.DecoratedCustomViewStyle();
builder.setStyle(style);

So I basically would like to apply the same left/right padding that is applied by the DecoratedCustomViewStyle, but without all that extra stuff.

Does anyone has experience how I can get the correct left-right padding for the notification?

Thanks in advance &
Best regards,
Manuel

S 7 Successor

Hello,
I am looking for a successor for my Samsung Gallaxy S7.
I have used the S7 very intensively in the last 3 years and have been quite satisfied with the hardware.
The only thing that bothered me was that it was too big.
I'm looking for a small, handy smartphone as a successor.
Which one can you recommend to me?
Unfortunately, those smartphones are getting bigger every year.
Even the S10e is just as big as the S7, eben thrugh everyone dass ihr S10e is small...
Is there a smaller device with a useful hardware?
Which one can you recommend to me? :)

Phone Answers When Touched- How To Stop?

Hello All!
I have a ZTE Maven using Android 5.1 Lollipop and AT&T Go Phone.
When the phone rings and I touch it to take it out of my pocket, the call is answered.
This is a new behavior. I used to have to swipe down on the screen to answer.

I have searched every setting & sub-setting on the phone with no luck.
Internet searching has many articles, some specific to Lollipop, but my phone does not have the buttons to press as shown in the articles.

Do any of you know how to turn off answering unless I swipe down?
Thanks Very Much for your help!
Paul

Filter

Back
Top Bottom