• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Wrapping or Parallax?

C

Chatterb0x

Guest
Hi all,
My game is mobile device based. The player itself does not move, but rather the objects behind it (think flappy bird) when the user swipes left/right.

I have a rock object that spans the entire level. People have suggested making it into a background. This is an option, though I already have backgrounds for separate purposes. I've tried wrapping the rock object when outside room but it does not wrap seamlessly (a gap between beginning/end).

This author used parallax to get the effect I want. Notice how that fence 'wraps' without interruption.
http://gamedevelopment.tutsplus.com...tive-way-to-add-depth-to-a-2d-game--cms-21510

What is the most economical way to accomplish this?
 

TheouAegis

Member
What do you mean you already have backgrounds for "separate purposes"? ... You have 8 backgrounds, how many are you actually using at once?

As for wrapping around the screen seamlessly, all you need to do is find the x coordinate once it has completely left and then add the distance from the edge of the room to the room_width. Do you have two rock objects in your room? I'm curious how you know there's an actual gap otherwise. Anyway, make sure the rock's origin is at (0,0). Then basically all you need is one conditional (in either Step or End Step):

Code:
if !bbox_right || !(room_width - x)
    x = room_width - abs(bbox_right);
 
C

Chatterb0x

Guest
Thanks for the responding. I'll explain why I'd prefer the rock remain an object. I have a day/night system using a dark and light background. Both are visible when game starts but alpha fluctuates. I thought placing them over the background would block the rock background.

I knew there was a gap because I've tried wrapping before.
 
S

SouthernPotato

Guest
The way I've handled situations where you need objects to seamlessly wrap is you have one object draw itself twice. So in the draw action, draw at x and x+ screen_width

Then in step:
If x < 0 { x += screen_width }

Ez
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Is the object for collisions or purely a graphical effect? Maybe it can move along with the room (so essentially be stationary within the view) and only DRAW the sprite moving? I'm thinking in particular that you could simply use the function draw_sprite_tiled to draw the sprite along the room, then use a custom x position to scroll it. Something like:

Code:
// CREATE
xpos = 0;

// STEP
xpos -= 5;

// DRAW
draw_sprite_tiled(sprite_index, image_index, xpos, y);
Using this draw function you don't have to worry about it wrapping since the sprite is being drawn tiles automatically for you and it should be seamless.
 

Yambam

Member
This is how I wrap instances:
Code:
x-=room_width*floor(x/room_width);
y-=room_height*floor(x/room_height);
Then I simply draw the sprite multiple times at (x,y), (x+room_width,y), (x,y+room_height), (x-room_width,y) and (x,y-room_height).
 
C

Chatterb0x

Guest
At the end of the day I've decided to implement wrapping backgrounds.
(HURR DURR DURR)
Sorry.

If it ain't broke, don't muck about. Plus, I can easily revamp my day/night system. My other problem, initially, was that the image lost quality after importing into GM. The sprite guy and I have apparently figured it out.

Thank you to everyone that contributed. There are some interesting mechanics for future projects.
 
C

Chatterb0x

Guest
Tr-tr-tr-triple post!
Well, dang.
The background and objects have the same hspeed but there is a delay between them when wrapping. Here's a handy gif to illustrate.
http://gph.is/2c3xGrf

Any ideas?
 
Last edited by a moderator:

Yal

🐧 *penguin noises*
GMC Elder
I've tried wrapping the rock object when outside room but it does not wrap seamlessly (a gap between beginning/end).
You could just add one more rock outside the room's right border to patch that up AFAIK (the built-in wrapping triggers once the object is completely outside the room so you need exactly one more to patch the gap), just don't actually click yes if GM asks you whether to remove objects outside the room when you close the room editor.
 

Yambam

Member
Maybe it is because you are assigning background_hspeed in the end step or draw event? Anyway I think you can solve this by doing background_x+=(same amount as object, e.g. after you have set the object hspeed, simply: hspeed.) Make sure you do this in only one of the tree instances (maybe by doing if (id==obj_tree.id), which will select the last placed tree in the latest GM:Studio), or you could do it in a seperate camera object...
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
Did you try using the sprite/background tiled functions? I posted the code... that should work fine and if there is a pause it's an issue with how you've made it. You really should post the code you are using to make the effect... it's not as hard to do as you seem to be making it!!!
 
C

Chatterb0x

Guest
Some of my code is used for testing mechanics.
Note: global_speed is a global var

obj_player
from STEP EVENT
//If player swipes RIGHT
case 1:
swipe_ready = 0;
image_xscale = 1;
image_speed = .25;
sprite_index = spr_playerslash;
image_index = 0;
global_speed = -10;

obj_blossom1
STEP EVENT

hspeed = global_speed;
OUTSIDE ROOM EVENT
Wrap horizontal when outside

obj_control
from STEP EVENT

if(game_start == 1){
background_alpha[2] += .010;

background_hspeed[2] = global_speed;
}
 
C

Chatterb0x

Guest
@Nocturne
Btw, to clarify my answer, the blossom object can be interacted with. The tree/rock background is purely graphical. I've tried your method and here is the result. Bear in mind I'm not super savvy with tiles.



obj_blossom2
DRAW EVENT
if(game_start == 1){
image_alpha += .05;
draw_sprite_tiled(spr_blossom2, 0, xpos, y);}

Edit:
Ah, you must be referring to the background graphic. Here is the description for draw_sprite_tiled.
This function will take a sprite and then repeatedly tile it across the whole view (or room if no view is defined), starting from the coordinates that you give in the function.
That's exactly what happens.
 
Last edited by a moderator:
C

Chatterb0x

Guest
How 'bout that.
We've nearly solved the problem. Game Maker by default wraps objects when they've entirely left the screen. I circumvented this by specifying a margin of 0 in the move_wrap function.

Blossom objects
STEP event
move_wrap(true,false,0);

http://gph.is/2crgXPf

The blossom objects do not sync perfectly with the background. They go slightly off kilter when swiping left or right. Suggestions?
 
Last edited by a moderator:
C

Chatterb0x

Guest
Bumping in case ya'll have a brainwave. In the meantime, I'm going to retry objects with 0 margin.
 

Yal

🐧 *penguin noises*
GMC Elder
You could manually check your position in the step event, and basically move room_width (plus/minus a few pixels) across the room when you cross a boundary (x > room_width or x < 0)... that way, you have more control and can adjust wrapping better in case you're a few pixels off. You could even wrap before you leave the room in case that looks better.
 
C

Chatterb0x

Guest
Is wrapping before leaving the room possible? I tried using a negative margin and the rock disappeared! Another contributor to the GameMaker Reddit suggested manually checking position. It just warps the rock object but I'll apply it to the blossoms.
 

Yal

🐧 *penguin noises*
GMC Elder
Is wrapping before leaving the room possible? I tried using a negative margin and the rock disappeared! Another contributor to the GameMaker Reddit suggested manually checking position. It just warps the rock object but I'll apply it to the blossoms.
It's possible if you handle the wrapping yourself, not sure whether the built-in version handles it. The trick is that you must make sure you never move from a 'wrap inside this zone' area into another... wrapping should always put you in a position where you can stay without triggering it again. The built-in wrapping place you exactly on the border of the room, so it doesn't technically move you out of the warp zone.
 
C

Chatterb0x

Guest
How would you attain this? As soon as even a pixel reaches the screen end I want that pixel to wrap. So far I'm forced to choose between wrapping an entire object, which looks more like it's warping!
 

Yal

🐧 *penguin noises*
GMC Elder
How about drawing the object twice when it gets near the edge? Apart from drawing it at its current position, you'd draw it at room_width + x if it's about to go past the left border of the room, and x - room_width if it's about to go past the right border. (And similar vertically if you wrap it vertically as well)
 
C

Chatterb0x

Guest
@Yal
I'll try it and keep you posted.

Thanks everybody for contributing. I may leave it as is. The experience won't be ruined because GM does not comply 100% with my vision. After all, the title is Blind Samurai. I'm making a game accessible to the visually impaired.
 
C

Chatterb0x

Guest
WINNER WINNER CHICKEN DINNER
http://gph.is/2cixohH

First, an apology to everyone that suggested making a duplicate. I implemented your idea last because I thought it meant making duplicate blossoms. Not so! It was a pixel perfect fit based on how GM wraps objects. Now there are two rock objects. They are identical sans step event. Observe obj_rock2.

if(obj_rock.x < view_xview){
visible=true;
x=obj_rock.x+sprite_width;
y=576;
hspeed=global_speed;
}

if(obj_rock.x > view_xview){
visible=true;
x=obj_rock.x-sprite_width;
y=576;
hspeed=global_speed;
}

It does chug slightly. Sadly, I may forego wrapping if it chugs too much after adding enemy/blood objects.
 
Top