• 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!

Windows Asteroids tutorial - objects disappearing

C

CountZer0

Guest
Hi all, sorry if this has been asked before but this one is driving me nuts.
I'm new to GM and have followed Shaun Spaldings Asteroid tutorial. I've embelished quite a bit (warp drive, change of sprites, bouncing rocks etc) but 1 bug is killing me but I can figure out.

Objects just disappear!

All the asteroids have a wrap in both directions when outside the room event/action and this seems to work. However, randomly asteroids that leave the playfield (room?) sometimes don't wrap and therefore seem to disappear and the room can't be 'cleared'.

I've added some test logic in that simply counts and displayed the number of instances present at every step and display the number to screen and when this bug occurs the count still says there are instances :/

What is supposed to happen (as per Shaun's tutorial) is that once all the asteroids are cleared this codes adds them again:

Code:
if (!instance_exists(obj_asteroid))
{
    instance_create(random(room_width),random(room_height),obj_asteroid);
    instance_create(random(room_width),random(room_height),obj_asteroid);
    instance_create(random(room_width),random(room_height),obj_asteroid);
    instance_create(random(room_width),random(room_height),obj_asteroid);
    instance_create(random(room_width),random(room_height),obj_asteroid);
    instance_create(random(room_width),random(room_height),obj_asteroid);
}
I've tested that this works by setting the T key to destroy all instances of obj_asteroid so I can see the them all get created again.

But I cannot for the life of me workout how/why some objects are leaving the room and not wrapping.
Anyone come across this before or might be able to point me in the right direction?

I've even just died (lost all 3 lives) without shooting and just left the game running and they slowly disappear...
 
D

Destroy

Guest
Oh, I think that this happens when an object is off the room both on x-axis and y-axis. I don't remember how did I fix this, but I'd recommend trying this:

1) Put the wrap action in step event. Shouldn't be necessary but... Yeah. If that doesn't work,
2) Use two wrap actions instead of one, set one of them to horizontal only and one to vertical only.

If neither works, use this code instead of wrap action:
Code:
x = (x + room_width) mod room_width;
y = (y + room_height) mod room_height;
You can run it in step event as it basically leaves x at x and y at y when inside room. This won't look that nice tho, so you might as well try this:
Code:
if(median(x, -sprite_width/2, room_width + sprite_width/2) != x) x = room_width - x;
if(median(y, -sprite_height/2, room_height + sprite_height/2) != y) y = room_height - y;
Again, you can run this in step event. I'm currently kinda sleepy so I can't explain well though :/ I can try to later, though :p
 
C

CountZer0

Guest
Thanks for the advice, much appreciated.
I tried all of your suggestions with the following results:

Option 1 - put the wrap action in the asteroid's step event. Seemed to work but now the asteroids don't fully leave the screen before they seem to blink out on one edge and start to appear on the other.
Option 2 - use 2 wrap events instead of one. Had no effect on the issue.
Option 3 - use code in step event had similar to effect to option option 1 but even jumpier.
Option 4 - seemed to work for one round but on round two 3 asteroids left the playfield and didn't come back :(rr

I thought I had it sussed at one point by using an 'Out of View' event which seemed to work for a moment and then back to disappearing asteroids.
The more I watch their behaviour the more I think it's something to do with the relationship between the movement and the space around the animated asteroid... I think their random movement/bounce is making it so that they sometime travel so slowly along the edge of the room that they aren't visible but still aren't registering as having left the room.
Going to test that by adding full colour to the sprite background :)
:( that did show any issues but I do think it might still be related.
 
Last edited by a moderator:
A

Ashurlee

Guest
I am also having this same issue, it also effects the player as well, i have tried various different solutions found throughout these forums but none seem to work.
I am new to this as well so this question may be a bit silly im not sure

but is there a way to set multiple screen wraps at different points outside the screen so if it does slip outside one screen wrap it will have another to pass through?
im guessing that could get messy and be hard on the games memory but right now after trying many things thats the best idea i can think of right now


I fount this piece of code on another similar thread to reproduce the wrap around feature:

Code:
if bbox_left >= room_width
    x -= room_width + bbox_right + 1 - bbox_left;
if bbox_right + 1 <= 0
    x += room_width + bbox_right + 1 - bbox_left;
if bbox_top >= room_height
    y -= room_height + bbox_bottom + 1 - bbox_top;
if bbox_bottom + 1 <= 0
    y += room_height + bbox_bottom + 1 - bbox_top;
It doesn't fix the bug but I have been sat here for two hours trying to figure out how to modify it so that you can extend its region so i could have this code running as well as the modified version so there are multiple passes just incase it does leave. But I have not been able to figure out how to do that.

I'll try putting it in the step event for now though and see if that makes a difference. I wont be able to tell straight away though, my brother can recreate the bug fairly well, i can't seem to force it into happening myself.
 
Top