简体   繁体   English

将瓷砖与Slick2D结合

[英]Combining tiles with Slick2D

I am working on a simple 2D game with use of Slick2D 我正在使用Slick2D制作一个简单的2D游戏

But I have one problem that shouldn't be one, but I can't find the correct answer anywhere. 但是我有一个问题不应该是一个问题,但是我在任何地方都找不到正确的答案。

My question is: How can I combine tiles of a spritesheet? 我的问题是:如何合并Spritesheet的图块? One tile is 32 x 32 pixels. 一格为32 x 32像素。 I have a sprite for the player that uses 3 tiles in height and one in width. 我有一个供玩家使用的精灵,它使用3个高度的瓷砖和1个宽度的瓷砖。 Now I want to display the whole player and I am wondering how I can say that the image of the player goes from tile (3,0) to (3,3) on the sheet. 现在,我想显示整个播放器,我想知道如何说播放器的图像从图纸上的(3,0)变为(3,3)。

How I define the spritesheet: 我如何定义Spritesheet:

public void init(GameContainer gc) throws SlickException {
      spritesheet = new SpriteSheet("res/sprite_sheet.png", 32, 32);

  }

How I render it: 我如何渲染它:

public void render(GameContainer gc, Graphics g) throws SlickException {

      map.render(200, 100);
      g.drawString("Collision: "+collides, 10, 60);
      g.draw(pointer);

      spritesheet.startUse();
      playerImage = //I need to combine them here I guess?
      spritesheet.endUse();
      playerImage.draw();

  }

Thanks for the help :) 谢谢您的帮助 :)

After trying around a lot I found out the solution for this. 经过大量尝试后,我找到了解决方案。

You can extend yourImageHere.draw() to yourImageHere.draw(x, y, width, height) x and y is the coordinate where your sprite on the image (spritesheet) starts, in pixels width and height defines the size of the image frome there. 您可以将yourImageHere.draw()扩展到yourImageHere.draw(x,y,width,height)x和y是图像(spritesheet)上的精灵开始的坐标,以像素为单位,width和height定义了图像的大小。那里。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM