parallaxbackground.java

来自「一个java的免费游戏引擎,里面有文档,和例子」· Java 代码 · 共 70 行

JAVA
70
字号
// Decompiled by Jad v1.5.7g. Copyright 2000 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/SiliconValley/Bridge/8617/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi 

package com.golden.gamedev.object.background;

import com.golden.gamedev.object.Background;
import java.awt.Graphics2D;
import java.awt.Rectangle;

public class ParallaxBackground extends Background
{

    private Background a[];
    private int b;

    public ParallaxBackground(Background abackground[])
    {
        a = abackground;
        b = abackground.length;
        b();
    }

    private void b()
    {
        for(int i = 0; i < b; i++)
        {
            if(a[i].getWidth() > getWidth())
                setSize(a[i].getWidth(), getHeight());
            if(a[i].getHeight() > getHeight())
                setSize(getWidth(), a[i].getHeight());
        }

    }

    public void setLocation(double d, double d1)
    {
        super.setLocation(d, d1);
        for(int i = 0; i < b; i++)
            a[i].setLocation((getX() * (double)(a[i].getWidth() - getClip().width)) / (double)(getWidth() - getClip().width), (getY() * (double)(a[i].getHeight() - getClip().height)) / (double)(getHeight() - getClip().height));

    }

    public void update(long l)
    {
        for(int i = 0; i < b; i++)
            a[i].update(l);

    }

    public void render(Graphics2D graphics2d)
    {
        for(int i = 0; i < b; i++)
            a[i].render(graphics2d);

    }

    public Background[] getParallaxBackground()
    {
        return a;
    }

    public void setParallaxBackground(Background abackground[])
    {
        a = abackground;
        b = abackground.length;
        b();
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?