简体   繁体   English

如何在Java中制作自定义鼠标光标?(Slick 2D)

[英]How to make a custom mouse cursor in Java?(Slick 2D)

Hello I'm making a game in Slick2D and I would like to create a custom cursor image for it. 您好,我正在用Slick2D制作游戏,我想为其创建一个自定义光标图像。 I would like to know what code and where I need to put it. 我想知道什么代码以及在哪里放置它。

package lame.game.j3;

public class Menu extends BasicGameState{

//what should I put here?

public Menu(int state){
}

public void init(GameContainer gc, StateBasedGame sbg) throws SlickException{
    //what should I put here?
}

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

//what should I put here?

}

public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{

//what should I put here?

}

public int getID(){
    return 0;
}

Thanks! 谢谢!

See the documentation for GameContainer.setMouseCursor . 请参阅GameContainer.setMouseCursor的文档。 You would want to put it in init(...) or in a different class, where the "StateBasedGame" or other game type is created. 您可能希望将其放在init(...)或创建“ StateBasedGame”或其他游戏类型的其他类中。 It depends on where you want the cursor to be used (only in this state, or for the whole game). 这取决于您要在何处使用光标(仅在此状态下,或在整个游戏中)。

Did it by myself, I put this in init(...): 由我自己完成,我将其放在init(...)中:

gc.setMouseCursor(cursor, hotSpotX, hotSpotY);

gc = my game container gc =我的游戏容器

cursor = a 32x32 image 光标= 32x32图片

hotSpotX/Y= an integer (0) hotSpotX / Y =整数(0)

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

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