Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Game Maker: Using an object as a background to make it Loop/Scroll

  • 08-10-2016 4:20pm
    #1
    Registered Users, Registered Users 2 Posts: 101 ✭✭


    Hey guys, I am trying to make a game similar to the Atari 2600 game Solaris, where in that game, it features a space segment that has the background move when the player moves. I found a roundabout way of doing this, by making the background an object rather than a background. I then assigned for that to move when I press the corresponding key. However I am still having some issues.

    I am trying to find a way to make the object loop when it reaches the edge of the room. I tried to make some code, but the best I could get was that the object instead becomes a blank square when it reaches the edge of the room. As well as this, the PlayerShip object disappears as soon as I press the keys for the background to move. Any ideas how I can fix these issues? The background object is as large as the room. Here is my lines of code for the background object:

    if (x<=0 )
    {
    x = room_width + 1;
    }

    else if(x >= room_width)
    {
    x = 1;
    }

    Then I have the drag and drop for the movement. Thanks!


Comments

  • Registered Users, Registered Users 2 Posts: 8,493 ✭✭✭RedXIV


    PKdude wrote: »
    Hey guys, I am trying to make a game similar to the Atari 2600 game Solaris, where in that game, it features a space segment that has the background move when the player moves. I found a roundabout way of doing this, by making the background an object rather than a background. I then assigned for that to move when I press the corresponding key. However I am still having some issues.

    I am trying to find a way to make the object loop when it reaches the edge of the room. I tried to make some code, but the best I could get was that the object instead becomes a blank square when it reaches the edge of the room. As well as this, the PlayerShip object disappears as soon as I press the keys for the background to move. Any ideas how I can fix these issues? The background object is as large as the room. Here is my lines of code for the background object:

    if (x<=0 )
    {
    x = room_width + 1;
    }

    else if(x >= room_width)
    {
    x = 1;
    }

    Then I have the drag and drop for the movement. Thanks!

    I'd need to look into gamemaker itself to help I think. There's no way the code you supplied above is enough to do the job. Regarding the ship disappearing, is it getting drawn behind the background image maybe?

    For the code above, is the value for X being updated elsewhere?


  • Registered Users, Registered Users 2 Posts: 101 ✭✭PKdude


    Sorry, there is little I can add to make it any clearer. I thought it was something to do with the depth of both objects but I'm unsure. That code is attached onto the background object. I think something in that script is interfering with the ship but because it's only the x axis, it's not effecting the y movement of the object.


  • Registered Users, Registered Users 2 Posts: 8,493 ✭✭✭RedXIV


    PKdude wrote: »
    Sorry, there is little I can add to make it any clearer. I thought it was something to do with the depth of both objects but I'm unsure. That code is attached onto the background object. I think something in that script is interfering with the ship but because it's only the x axis, it's not effecting the y movement of the object.

    The depth of the objects may be the cause of losing the ship. In gamemaker, the lower the depth value, the further to the front. The problem is everything has a default depth of 0 so maybe set the background object to a depth of say 10 and see if that keeps your ship in view.

    Will have a look at the scrolling thing now in a few mins


  • Registered Users, Registered Users 2 Posts: 101 ✭✭PKdude


    I tried that but it didn't work. The player ship is viewable when I'm not moving the background object with the key press, but as soon as I press the key, it disappears and only reappears when i let go.


  • Moderators, Category Moderators, Computer Games Moderators Posts: 52,406 CMod ✭✭✭✭Retr0gamer


    I don't think you need objects for this at all. Create your background with tiles and in the creation event put the tile id into an array.

    When a button is pressed iterate through the array adjusting the X and y positions accordingly.

    To make it loop make it so if a tile goes a certain distance off screen move it to a position on the opposite side (ensuring it lines up with the tiles on that side). Also account for tiles going over this limit diagonally (can end up with a tile going over the X and y limit at the same time).

    If you can't do a creation event with tiles then maybe objects would be better.

    I'd try and move away from drag and drop if you want to get good at gamemaker. It can introduce its own issues later that make it harder to debug issues.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 101 ✭✭PKdude


    Okay, I ended up using view on the Player object and changed the background object, to an actual background (rather than just an object). Now I am trying to figure out, how to loop a room. Right now the camera works by following the player, but when it reaches the edge of the room, the camera stops following the player, while the player goes through the edge of the room. Is there some way I can make the background constantly loop?


  • Moderators, Category Moderators, Computer Games Moderators Posts: 52,406 CMod ✭✭✭✭Retr0gamer


    This is tricky one but I know what to do to sort it. I was looking at Solaris and know the stage you are talking about.

    Your problem is you are scrolling the camera view. The camera needs to stay static.

    Your directional keys control your ship as normal.

    When the ship reaches the left or right limits of its movement instead of scrolling the camera view, scroll the background. The ship essential stops moving at the X limits of its movement range. Enemies, bullets and obstacles will also have to move with this so add an extra X component to their movement, play around with this until you are happy and it feels natural.

    To get the looping working as I said above once a background tile, or enemy reaches a limit outside the screen, reset its position to the opposite sides limit, it sort of gets recycled.

    A lot of these older games didn't have the memory to have large rooms so had to essentially fake it like this. The'room ' is actually only one screen big but the enemy's and background scroll depending on the ship position and the player joystick input.


Advertisement