Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @objc func heartFlurry()
- {
- let heartImage = UIImage(named: "heartWhite")
- let heartImageView = UIImageView(image: heartImage)
- let screenSize = UIScreen.main.bounds
- let heartWidth = Int(heartImage!.size.width)
- let heartHeight = Int(heartImage!.size.height)
- let randomX = arc4random_uniform(UInt32(screenSize.width))
- heartImageView.frame = CGRect(x: Int(randomX) - Int(Double(heartWidth) * 0.5), y: Int(screenSize.height) + heartHeight, width: heartWidth, height: heartHeight)
- view.addSubview(heartImageView)
- let randomIntFrom0To4 = Int.random(in: 1..<6)
- print(randomIntFrom0To4)
- self.updateLove()
- self.playSound(sound: "pop_(randomIntFrom0To4)")
- UIView.animate(withDuration: 1.5, animations: {
- heartImageView.center = CGPoint(x: heartImageView.center.x, y: CGFloat(-heartHeight))
- }) { (finished: Bool) in
- heartImageView.removeFromSuperview()
- }
- }
- void heartFlurry() {
- Drawable heart = getResources().getDrawable( R.drawable.heart );
- View v = new ImageView(getBaseContext());
- ImageView imageView;
- imageView = new ImageView(v.getContext());
- imageView.setImageDrawable(heart);
- Integer heartWidth = heart.getIntrinsicWidth();
- Integer heartHeight = heart.getIntrinsicHeight();
- Display display = getWindowManager().getDefaultDisplay();
- Point size = new Point();
- display.getSize(size);
- int width = size.x;
- int height = size.y;
- Log.e("Width", "" + width);
- Log.e("height", "" + height);
- final int randomX = new Random().nextInt(size.x);
- Log.e("randomX", "" + randomX);
- // RelativeLayout. though you can use xml RelativeLayout here too by `findViewById()`
- final RelativeLayout relativeLayout = new RelativeLayout(this);
- // Setting layout params to our RelativeLayout
- RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(size.x, size.y);
- // Setting position of our ImageView
- layoutParams.leftMargin = randomX;
- layoutParams.topMargin = 500;
- // Finally Adding the imageView to RelativeLayout and its position
- relativeLayout.addView(imageView, layoutParams);
- ObjectAnimator animationY = ObjectAnimator.ofFloat(imageView, "translationY", -size.y);
- animationY.setDuration(500);
- animationY.start();
- new CountDownTimer(500, 1000) {
- public void onTick(long millisUntilFinished) {
- }
- public void onFinish() {
- relativeLayout.removeAllViews();
- }
- }.start();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement