How do I make a phase walk along with a character in JFrame Java?

-1

I wanted to know if how to make a camera to character when it reaches the end of the panel start to go next to the character, because when setting a size this.setSize(500,500); the character when passing this mark it disappears and if you limit the movement it stays stuck in that square.

    
asked by anonymous 06.06.2016 / 15:27

1 answer

0

As you have a large JPanel, you may have already added it to a JScrollPane, so you can "see" the entire JPanel, according to the bar, if you have not done so, search JScrollPanes, but basically you will do the following:

Container cp=getContentPane();
JPanel pnJogo=new JPanel();//aqui vai ficar a interface do jogo
JScrollPane sc=new JScrollPane(pnJogo);//adicionando o painel ao ScrollPane

After doing this, you can set the value of your Scroll as you add it, but from that point on, the setValue criterion is up to you!

final JScrollBar bar1 = seuScroll.getHorizontalScrollBar();
bar1.setValue(10);//isso pode estar dentro de um for, ou um ActionListener também, por exemplo.

And, it would be a good idea too, you block the ScrollPane, so that the user can not "analyze" the phase before going forward, therefore, it would take the "emotion" of the game, I apologize, but this is an idea, I do not know how to "block" the bar (if anyone knows, feel free to edit the answer)

An example of how you can do this, then configures the character for walking, you increase the value of the scrollBar

    
07.06.2016 / 13:30