Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Need help fixing/making scrolling maze engine edit3
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
Hello there. I am far into Slimeith's quest 3 development when I went to finally work on the game's basic movement system. However I can not get it to work. A project with what I have of the broken system is here
.
I am trying to make a scrolling game engine where the game stops scrolling where there is no more tiles left, then Slimeith starts scrolling until he hits the edge of the screen, or goes back to the center letting the stage scroll again. Slimeith scrolling on his own works perfectly in isolation, however when it activates in the going left script the game starts lagging to a screeching halt.
Other notes: The locations of the tiles in this are stored as a 12 digit number. The first and sixth digit telling whether it is positive or negative and the rest telling where it should go. All tiles are in a 480 by 360 grid. However in the borders the first and fifth digits tell whether it is positive or negative since the second and seventh digits were always 0 in Level one. Every NPC in the game depends on StageX and Y to tell where they should go. In area border a tile's number times two is it's Y position item on the list, and the Y item's number minus one is the X position item on the list.
Thank you if you can fix this. This means a lot to me and I will be eternally thankful as this is a important part of the game. I worked really hard on the rest of the game, and it wouldn't be complete until this is fixed.
I am trying to make a scrolling game engine where the game stops scrolling where there is no more tiles left, then Slimeith starts scrolling until he hits the edge of the screen, or goes back to the center letting the stage scroll again. Slimeith scrolling on his own works perfectly in isolation, however when it activates in the going left script the game starts lagging to a screeching halt.
Other notes: The locations of the tiles in this are stored as a 12 digit number. The first and sixth digit telling whether it is positive or negative and the rest telling where it should go. All tiles are in a 480 by 360 grid. However in the borders the first and fifth digits tell whether it is positive or negative since the second and seventh digits were always 0 in Level one. Every NPC in the game depends on StageX and Y to tell where they should go. In area border a tile's number times two is it's Y position item on the list, and the Y item's number minus one is the X position item on the list.
Thank you if you can fix this. This means a lot to me and I will be eternally thankful as this is a important part of the game. I worked really hard on the rest of the game, and it wouldn't be complete until this is fixed.
Last edited by muellly (Oct. 19, 2017 01:29:28)
- gtoal
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
Assuming your basic scrolling works, the mechanics of what you want to do are easy…
The meta rule is place the world first assuming the character is in the center of the screen, then place the character. But you place the world according to where the character is, *unless* that would position a world edge inside the screen. When that happens, correct it to be on the screen edge. Then place the character. As long as you can do your x/y -> screen x/screen y offset calculations properly, it all just works..
Also you don't need to force your character to be in the center. You can place a box around him that he can move in and he moves on the screen until he touches those threshold edges (not the screen edges). At that point, force the scrolling except use his actual screen x,y rather than 0,0 as your virtual screen center. If you implement this rather than the simpler scheme with the character in the center, you can set the scrolling threshold to be a 0-sized box at 0,0 and get the same effect, yet allowing you to move to a partial confinement or no constraint at all simply by increasing the size of that trigger box,
The meta rule is place the world first assuming the character is in the center of the screen, then place the character. But you place the world according to where the character is, *unless* that would position a world edge inside the screen. When that happens, correct it to be on the screen edge. Then place the character. As long as you can do your x/y -> screen x/screen y offset calculations properly, it all just works..
Also you don't need to force your character to be in the center. You can place a box around him that he can move in and he moves on the screen until he touches those threshold edges (not the screen edges). At that point, force the scrolling except use his actual screen x,y rather than 0,0 as your virtual screen center. If you implement this rather than the simpler scheme with the character in the center, you can set the scrolling threshold to be a 0-sized box at 0,0 and get the same effect, yet allowing you to move to a partial confinement or no constraint at all simply by increasing the size of that trigger box,
Last edited by gtoal (Sept. 24, 2017 02:55:04)
- deck26
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
See if this helps https://scratch.mit.edu/projects/51479882/
I think it helps to think of scrolling as a ‘window’ onto a real world. The coordinates of things in the real world don't change but the position of the window does. In your case the window cannot go beyond certain bounds. In most cases the window is centred on the player's character but that doesn't have to be the case as @gtoal says.
I think it helps to think of scrolling as a ‘window’ onto a real world. The coordinates of things in the real world don't change but the position of the window does. In your case the window cannot go beyond certain bounds. In most cases the window is centred on the player's character but that doesn't have to be the case as @gtoal says.
- DaEpikDude
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I made a test script that uses a “camera” sprite that handles all the scrolling (that also acts as a border so you can't see the sprites piling up at the sides). I made a “scroll align” block (run without screen refresh) that essentially moves the camera back into reasonable bounds that you input.
define scroll align (x bound) (y bound)As long as the block is run without screen refresh, it should work. You could also modify it so that there's an upper and lower bound instead of the lower bound always being 0 if you want.
if <(scroll x) < [0]> then
repeat until <not <(scroll x) < [0]>>
change [scroll x v] by (1)//Do this again for scroll Y
end
end
if <(scroll x) > (x bound)> then
repeat until <not <(scroll x) > (x bound)>>
change [scroll x v] by (-1)//Do this again for scroll Y + Y bound
end
end
forever//Game loop stuff
...
scroll align (some bound) (some other bound)
end
Last edited by DaEpikDude (Sept. 24, 2017 13:30:41)
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
While I'm still confused if I'm understanding correctly I should move the scripts that control scroll X and Y to the stage. I will also make an extra list for the current border taken from the border list I have now to make the code shorter. When moving a direction such as right it checks everything in the border list, first making sure that the tile it's checking is the same Y then checking to see if there is any acceptable Xs that would let it move. If there is an acceptable X it changes the X position. If no Xs are acceptable it sends a broadcast (or should it be a variable) that tells Slimeith that it can move and keeps moving by changing it's own X position until it is zero, then it sends another broadcast telling the background it should start scrolling X again(or should the stage check for when Slimeith's X position is zero). Then do the same thing but for the Y value. I'm just asking here first before it turns out I didn't understand correctly, and made the coding worse.
@DaEpikDude
Thank for trying to give me a script for this, however it won't work (unless I'm not understanding something) because most of my areas are not squares or rectangles. My biggest room's layout is
with the green and yellow pixels being the tiles. (Also by combining Powercon5's sizing script with adding mostly transparent pixels to the outer sides of the costumes my sprites don't pile up on the sides.)
@DaEpikDude
Thank for trying to give me a script for this, however it won't work (unless I'm not understanding something) because most of my areas are not squares or rectangles. My biggest room's layout is

- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
Thanks to Echo_GAMER_516 the collison was fixed so that is one thing out of the way.
Okay due to a lack of response I am going to try to implement what I just said. I hope I don't make the system worse. I saved a backup just in case.
Okay due to a lack of response I am going to try to implement what I just said. I hope I don't make the system worse. I saved a backup just in case.
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I tried what I said, and I am stuck again. I updated the first post with my updated code.
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I tried adding in allowing Slimeith to move, and it is very laggy(and probably glitchy). I have edited the first post to include this, and the going left for Slimeith is fully commented.
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I still have no idea what to do. My two biggest problems right now is that going left out of bounds where Slimeith moves on his own lags tremendously, and I have no idea what to check for the scroll being in scroll bounds.
- MasterOfTheTiger
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I am working on fixing it. I hope I can do it.
- Uniquename1
-
100+ posts
Need help fixing/making scrolling maze engine edit3
You have a bunch of stuff scattered around so it's hard to tell whats doing what. I made a quick experiment just of going to the edge of the scrolling then going to the edge of the screen and back to the center before going back the other way. Basically used and and or's to determine when it should move based on world size, x position and scrollX but not collisions. I'll try to add a collision if I have time.
https://scratch.mit.edu/projects/178140718/
https://scratch.mit.edu/projects/178140718/
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
You have a bunch of stuff scattered around so it's hard to tell whats doing what. I made a quick experiment just of going to the edge of the scrolling then going to the edge of the screen and back to the center before going back the other way. Basically used and and or's to determine when it should move based on world size, x position and scrollX but not collisions. I'll try to add a collision if I have time.I organized my code so hopefully it is easier to understand. One of my main problems making this engine is that I have no idea what to put for when it check if you can scroll or not. It would be easier if it was just positive numbers, but there are, also negative coordinates for tiles too. I have areas where you would be able to scroll up when your Y position is 70 when your X is -200, but you can't scroll up when your X is 400. I have no idea how to code that. All I know is that I want the game to read from the borders list which areas it can scroll in.
https://scratch.mit.edu/projects/178140718/
- gtoal
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
The background and the player are placed according to world coordinates. The scrolling is triggered by screen coordinates. Do everything in world coordinates except the display routine and the triggering of scrolling movement.
I think you need to put aside your game and just work on a basic scrolling engine with tiles for the background and a single square for the player.
Simplify the problem (and simplify your description of what is going wrong) to get more useful help.
Once you get a basic scrolling engine working, adding your game and more characters/objects to it should be a lot easier.
G
I think you need to put aside your game and just work on a basic scrolling engine with tiles for the background and a single square for the player.
Simplify the problem (and simplify your description of what is going wrong) to get more useful help.
Once you get a basic scrolling engine working, adding your game and more characters/objects to it should be a lot easier.
G
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I just realized something. I somehow managed to code the coordinates of where the tiles go, and the areas the scroll is allowed to go to reversed, so -200X in tile coordinates would be 200X in the allowed to scroll. The positive scrolling for left works perfectly, however it stops working completely in the negative Stage Xs.
@gtoal I just simplified the engine by temporally taking out collision, and the part where Slimeith moves on his own.
Edit:Yes! I think I just perfected going left. It appears to work in negative coordinates too now.
Edit again: I have not perfected left. It only detects the border farthest out at the moment.
@gtoal I just simplified the engine by temporally taking out collision, and the part where Slimeith moves on his own.
Edit:Yes! I think I just perfected going left. It appears to work in negative coordinates too now.
Edit again: I have not perfected left. It only detects the border farthest out at the moment.
Last edited by muellly (Oct. 12, 2017 00:46:08)
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
Okay I tried to fix the left which turns out didn't work, and it is still having problems. Mostly with the downwards tiles.
Last edited by muellly (Oct. 13, 2017 01:30:35)
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
Okay I managed to perfect scrolling left for the stage! However I have came across a new problem. Whenever Slimeith scrolls on his own. Slimeith scrolling on his own works perfectly in isolation, however when it activates in the going left script the game starts lagging to a screeching halt.
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
I am still stuck. My main problem is that the engine lags badly and stops working when you go to a part where Slimeith is suppost to scroll. I believe this may have something to do with it being a broadcast and wait block inside of a custom block however I am not sure.
- Uniquename1
-
100+ posts
Need help fixing/making scrolling maze engine edit3
I don't know all the rules for custom blocks but i have seen them get stuck, cause lag and a game to stop. I can't find the script you mean. In what sprite and whats the name of the custom block?
In general it looks like you have things in custom blocks that don't need to be like define delete this clone and it's hide and delete and one defines a broadcast and broadcasts. So it may not need to be in custom blocks at all also unchecking run without screen refresh might allow the custom block to work.
In general it looks like you have things in custom blocks that don't need to be like define delete this clone and it's hide and delete and one defines a broadcast and broadcasts. So it may not need to be in custom blocks at all also unchecking run without screen refresh might allow the custom block to work.
- muellly
-
1000+ posts
Need help fixing/making scrolling maze engine edit3
It was the custom block L in Background. I tried switching it to run with screen fresh but all that did was make the normal movement slower. There is a custom block in backdrop that hides and deletes a clone because I want to hide every instance of background, sometimes when it doesn't scroll it needs to hide, and I want the original to run code after deleting all of the clones. The define broadcasts are in the collision detection sprites, something that Echo_GAMER_516 made. I am yet to implement collision and clean up those scripts yet as right now I'm trying to figure out how to let Slimeith scroll on his own correctly.
Playing around I was able to make it so Slimeith moves on his own past -10 X but it still lags horribly.
Edit: Success! I was able to fix it by separating the script that checks and allows Slimeith to move on his own from the L script. I will now move on to collision.
Playing around I was able to make it so Slimeith moves on his own past -10 X but it still lags horribly.
Edit: Success! I was able to fix it by separating the script that checks and allows Slimeith to move on his own from the L script. I will now move on to collision.
Last edited by muellly (Oct. 26, 2017 00:11:31)
- Discussion Forums
- » Help with Scripts
- » Need help fixing/making scrolling maze engine edit3