Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » Scrolling from Top View Problem
- longj
- Scratcher
14 posts
Scrolling from Top View Problem
I am doing a top-view scrolling game, called Architect, but to release it, I need to fix one bug. I have houses that you can put down, but they overlap when they go off of the screen, check it out if you need to. I might have a few ideas, but I can't get it to work
'
'
- ryandw
- Scratcher
62 posts
Scrolling from Top View Problem
There is not really a way to fix that as I know.
Ryandw
Look here for some features: http://scratch.mit.edu/studios/433126/
Need a Encoder/Decoder? Try this one: http://scratch.mit.edu/projects/22883592/#player
if <(Need help?) = [true]> then
ask [for help!] and wait
end
- DanloVorje
- Scratcher
100+ posts
Scrolling from Top View Problem
Okay, I think I know what you want here…
Give each house a set of personal variables for its “Real World” x and y values. Create a set of global variables for the current x and y location of the center of the screen. What we're doing here is creating a coordinate system to use in the game that is separate from the coordinate system used by the screen. The screen can only keep track of positions within the bounds of the screen, but with variables we can extend the boundaries of the game world outside of what is visible.
So here's our variable list:
When you create a clone of the house, that clone will have its own values for *X and *Y. You can set them manually or work backwards from the position-determining script below to figure out how *X and *Y correlate with CameraX, CameraY, and the x and y positions of the mouse-pointer.
Each house clone would have a script like this:
For scrolling, you would have scripts that change CameraX and CameraY, not *X or *Y.
The sprites will pile on top of one another when they're pushed to the edge of the screen, but when you walk back to them they should retain their original starting points relative to each other.
Hope this helps!
–Danlo
Give each house a set of personal variables for its “Real World” x and y values. Create a set of global variables for the current x and y location of the center of the screen. What we're doing here is creating a coordinate system to use in the game that is separate from the coordinate system used by the screen. The screen can only keep track of positions within the bounds of the screen, but with variables we can extend the boundaries of the game world outside of what is visible.
So here's our variable list:
(*X)(^I typically use the * prefix to mark sprite-specific variables. You can use your own naming conventions.)
(*Y)
(CameraX)
(CameraY)
When you create a clone of the house, that clone will have its own values for *X and *Y. You can set them manually or work backwards from the position-determining script below to figure out how *X and *Y correlate with CameraX, CameraY, and the x and y positions of the mouse-pointer.
Each house clone would have a script like this:
when I start as a clone
forever
go to x: ((*X) - (CameraX)) y: ((*Y) - (CameraY))
end
For scrolling, you would have scripts that change CameraX and CameraY, not *X or *Y.
The sprites will pile on top of one another when they're pushed to the edge of the screen, but when you walk back to them they should retain their original starting points relative to each other.
Hope this helps!
–Danlo
What I'm working on right now: Isle of Dolor
- longj
- Scratcher
14 posts
Scrolling from Top View Problem
Okay, I think I know what you want here…
Give each house a set of personal variables for its “Real World” x and y values. Create a set of global variables for the current x and y location of the center of the screen. What we're doing here is creating a coordinate system to use in the game that is separate from the coordinate system used by the screen. The screen can only keep track of positions within the bounds of the screen, but with variables we can extend the boundaries of the game world outside of what is visible.
So here's our variable list:(*X)(^I typically use the * prefix to mark sprite-specific variables. You can use your own naming conventions.)
(*Y)
(CameraX)
(CameraY)
When you create a clone of the house, that clone will have its own values for *X and *Y. You can set them manually or work backwards from the position-determining script below to figure out how *X and *Y correlate with CameraX, CameraY, and the x and y positions of the mouse-pointer.
Each house clone would have a script like this:when I start as a clone
forever
go to x: ((*X) - (CameraX)) y: ((*Y) - (CameraY))
end
For scrolling, you would have scripts that change CameraX and CameraY, not *X or *Y.
The sprites will pile on top of one another when they're pushed to the edge of the screen, but when you walk back to them they should retain their original starting points relative to each other.
Hope this helps!
–Danlo
This should work, I'll try it, but there is an infinite house number, (Or the number of clones scratch will allow) so, do I need one for EVERY clone? If so, check out Architect, maybe make a remix that I can take a sprite from? I'll need to make a very small number of houses. Can you make the variables on your own project, and maybe set a house limit to 20-30? I'm not sure I'll be able to do very much, if I can't, I'll set the sprite sizes to be a lot smaller, so I can fit more on. Thanks though, I may follow you
- DanloVorje
- Scratcher
100+ posts
Scrolling from Top View Problem
This should work, I'll try it, but there is an infinite house number, (Or the number of clones scratch will allow) so, do I need one for EVERY clone? If so, check out Architect, maybe make a remix that I can take a sprite from? I'll need to make a very small number of houses. Can you make the variables on your own project, and maybe set a house limit to 20-30? I'm not sure I'll be able to do very much, if I can't, I'll set the sprite sizes to be a lot smaller, so I can fit more on. Thanks though, I may follow you
Every time you make a clone, that clone inherits any personal variables its parent sprite had. If you then modify those variables in a script that starts with
when I start as a cloneit will only modify the variables for that clone. You don't have to make a set of variables for each clone, because the clones will automatically do that when you use
create clone of [myself v]
Take a look inside this little demo project to see it in action:
http://scratch.mit.edu/projects/19013685/
–Danlo
What I'm working on right now: Isle of Dolor
- Discussion Forums
- » Help with Scripts
- » Scrolling from Top View Problem