I’m making a Sonic Side Scroller as an example for my students. I have two issues. The second issue is related to the enemies scrolling. Also, a minor issue: I have the ground looping and can’t seem to get the math right for seamless looping. I can’t remember how to do that. Help with that would be appreciated as well.
What I expect to happen: Enemies should loop on the screen and randomize their X position either when they touch each other, Sonic, or when they scroll off the screen. What actually happens: They do loop on the x-axis, but they also randomize on the y-axis. I have my rings doing that, but the code for enemies doesn’t seem to include anything about the y-axis. What I’ve tried: I have scanned every line of code for anything related to motoBug, crabmeat, spikes, or moledrill and don’t see anything related to the y-axis.
Hello, this is a very neat game! I am not seeing the issue with the randomization of the x axis for the enemies. Maybe you already fixed it or maybe I’m missing something. Could you give a little more information if you’re still seeing the issue?
It’s not the x-position that I was concerned with. The enemies loop on the x-axis, but they also seem to randomize their y-position sometimes though I don’t see where in the code it does this.
It looks like you figured out your enemy y positions. When they were added to the group, motobug became enemies[0], crabmeat became enemies[1], moledrill became enemies[3], etc. The x and y positions are then set in different blocks of code using for loops. The x positions for each are reset in the hit() function on line 70. You know this already because it is only resetting their x and not the y positions.
I think I got your background to loop. I think that is what your next question was. I set the bg2 x position so that is always relative to the first bg x position:
var bg = createSprite(200, 200);
bg.setAnimation(“1”);
var bg2 = createSprite(bg.x+400, 200);
bg2.setAnimation(“2”);
Then in the background() function, I did also set the movement and positioning for bg2 relative to bg:
function gameBackground() {
textVisible = false;
bg.velocityX=-1;
bg2.velocityX=-1;
bg2.x=bg.x+400;
if (bg.x < -200) {
bg.x = 200;
}
}
It seems to be working in this version but I didn’t play a full game:)