游戏引擎理论与实现系列04-画线和裁剪

画线算法和裁剪算法集成

关于画线(draw line) 和Clipping 的算法,请参考另外两篇文章, 其中有非常详细的介绍。

本节主要讨论如何集成。在Game.java, 增加了对应的画线和裁剪逻辑

    private void render() {
        BufferStrategy bs = this.getBufferStrategy();
        if (bs == null) {
            this.createBufferStrategy(3);
            return;// skip one render
        }

        //populate the bitmap
        Bitmap floors = ImageLoader.sprites;
        this.screen.render(ticker,floors);


        //draw the line
        Line line = new Line(10, 10, 60, 80, 255<<8);
        Clipping clip= new Clipping();
        clip.setArea(0, 0, 64, 68);
        clip.clipLine(line);
        line.draw(this.screen);

        //copy from the screen bitmap to screen buffer
        int[] pixels =this.screen.getPixels();
        for (int i = 0, len = pixels.length; i < len; i++) {
            this.screenPixels[i] = pixels[i];
        }

        Graphics g = bs.getDrawGraphics();
        g.drawImage(this.screenImage, 0, 0, WIDTH * SCALE, HEIGHT * SCALE, null);
        g.dispose();
        bs.show();
    }

因为本节只是介绍如何使用, 因此非常的简单明了. 下一节我们将介绍更有意思的主题精灵(Spirit).

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值