Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Both Confetti only come from the left #77

Closed
wmhtet opened this issue Apr 5, 2017 · 7 comments
Closed

Both Confetti only come from the left #77

wmhtet opened this issue Apr 5, 2017 · 7 comments

Comments

@wmhtet
Copy link

wmhtet commented Apr 5, 2017

Somehow, both confetti only come from the top left even though the view emiter is properly on left and right of screen top in layout file. Swapping the two ParticleSystem constructors to see if the later constructor(left) is overriding the former constructor(right). It is not the case. For now, I have change the min/max angle to have spread out confetti

    new ParticleSystem(this, 80, R.drawable.confeti2, 10000)
            .setSpeedModuleAndAngleRange(0f, 0.1f, 0, 0)
            .setRotationSpeed(144)
            .setAcceleration(0.000017f, 90)
            .emit(findViewById(R.id.emiter_top_right), 7);

    new ParticleSystem(this, 80, R.drawable.confeti3, 10000)
            .setSpeedModuleAndAngleRange(0f, 0.1f, 0, 0)
            .setRotationSpeed(144)
            .setAcceleration(0.000017f, 90)
            .emit(findViewById(R.id.emiter_top_left), 7); 
@plattysoft
Copy link
Owner

You need to create the particle system after the views are measured, see #22

@wmhtet
Copy link
Author

wmhtet commented Apr 5, 2017

Thanks for the nice job on this library. I have followed the link and now I am using the following code to address the issue.

    final View rootView = findViewById(android.R.id.content);
    ViewTreeObserver viewTreeObserver = rootView.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                new ParticleSystem(WelcomeActivity.this, 80, R.drawable.confeti2, 10000)
                        .setSpeedModuleAndAngleRange(0f, 0.1f, 180, 180)
                        .setRotationSpeed(144)
                        .setAcceleration(0.000017f, 90)
                        .emit(findViewById(R.id.emiter_top_right), 8);

                new ParticleSystem(WelcomeActivity.this, 80, R.drawable.confeti3, 10000)
                        .setSpeedModuleAndAngleRange(0f, 0.1f, 0, 0)
                        .setRotationSpeed(144)
                        .setAcceleration(0.000017f, 90)
                        .emit(findViewById(R.id.emiter_top_left), 8);
            }
        });

@wmhtet
Copy link
Author

wmhtet commented Apr 8, 2017

Can I commit the following two codes? It requires min SDK to increase to 16 tho.

<FrameLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/confetti_layer">
    <View android:id="@+id/emiter_top_left"
        android:layout_gravity="top|left"
        android:layout_marginTop="-20dp"
        android:layout_width="1dp"
        android:layout_height="1dp" />

    <View android:id="@+id/emiter_top_right"
        android:layout_gravity="top|right"
        android:layout_marginTop="-20dp"
        android:layout_width="1dp"
        android:layout_height="1dp" />
</FrameLayout>

<TextView
    android:text="@string/app_name"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    style="@style/Base.TextAppearance.AppCompat.Large"
    android:layout_gravity="center"/>

package com.plattysoft.leonids.examples;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewTreeObserver;

import com.plattysoft.leonids.ParticleSystem;

public class OnCreateBehindLayerActivity extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_on_create_behind_layer);
    final View rootView = findViewById(android.R.id.content);
    ViewTreeObserver viewTreeObserver = rootView.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
        viewTreeObserver.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
            @Override
            public void onGlobalLayout() {
                rootView.getViewTreeObserver().removeOnGlobalLayoutListener(this);

                new ParticleSystem(OnCreateBehindLayerActivity.this, 80, R.drawable.confeti2, 10000, R.id.confetti_layer)
                        .setSpeedModuleAndAngleRange(0f, 0.1f, 180, 180)
                        .setRotationSpeed(144)
                        .setAcceleration(0.000017f, 90)
                        .emit(findViewById(R.id.emiter_top_right), 8);

                new ParticleSystem(OnCreateBehindLayerActivity.this, 80, R.drawable.confeti3, 10000, R.id.confetti_layer)
                        .setSpeedModuleAndAngleRange(0f, 0.1f, 0, 0)
                        .setRotationSpeed(144)
                        .setAcceleration(0.000017f, 90)
                        .emit(findViewById(R.id.emiter_top_left), 8);
            }
        });
    }
}

}

@bassam2
Copy link

bassam2 commented Dec 8, 2017

how to stop after one time play?

@plattysoft
Copy link
Owner

@bassam2 I assume you are asking about using oneShot instead of emitter, but commenting on an unrelated issue in confusing at the very least.

@bassam2
Copy link

bassam2 commented Dec 10, 2017

Hello @plattysoft Thank you for your reply & support
no I am asking about Confetti I want to stop after one count play
thanks

@plattysoft
Copy link
Owner

@bassam2 this issue is about not starting from the proper place.
You are asking for how to use the library in an issue, which is supposed to be a defect, that's why it is unrelated.
Anyway, you either want to use oneShot as I suggested or use a timer and call stopEmitting.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants