2

So I am trying to create a 2D side-scrolling javafx game.

So far I used AnimationTimer to control movement of my character. But now I am kind of stuck trying to make the stage move.

I can move non-interactive elements using AnimationTimer again. But I am lacking an idea for how should I generate interactive elements in game.

For example, lets say player walks a lot of steps and reaches to take a pickup. Now how do I put this pickup in stage so it is somewhere later in game. To try explain my problem better, consider this pesky image I drew in paint:

enter image description here

Initially, only the screen between green bounds is visible to player. The player must walk forward (and hence the screen must walk forward too) and should find that pickup between two walls. How do I place pickup outside scene's visible view so it comes into view only when player reaches it?

user3271166
  • 573
  • 1
  • 6
  • 17

1 Answers1

0

The easy way: You add everything to the scene and give it absolute coordinates. You move the player by changing its coordinates in the scene. Depending on the position of the player you start scrolling. While you scroll the background you also move all other objects about the same x and y coordinates. The visible view has a given width and height. Depending on the player's position, view width/height and object range the objects become visible during scrolling.

Roland
  • 18,114
  • 12
  • 62
  • 93
  • 1
    I am aware of this approach... But there are two problems: I am making for variable screen sizes, hence I cannot hard-code the location of these pickups, instead it has to be relative to width/height of stage (some help, if possible, even if an example would be good regarding this too). Next problem is having too many elements to move. Isn't there a way that I put them all in some container and move that container instead? Because I would like to avoid so many tasks at pulse updates..... – user3271166 Feb 25 '16 at 14:44
  • If you create example code, it's more likely you get help. Variable screen sizes aren't a problem. Of course you can put it all in various containers (eg Pane), but optimization is usually a process that happens when everything works. – Roland Feb 25 '16 at 15:50