I have made a scrolling background which moves up, down, left and right. This is so you can see an empty shell of a building, and move around it from birds eye view.
[blocks]
<set{ PositionX }to(<x position>)
<set{ PositionY }to(<y position>)
<forever>
<set x to( <{ ScrollX }> + <{ PositionX }>
<set y to( <{ ScrollY }> + <{ PositionY }>
<end>
[/blocks]
The first part comes after the "follow cursor, when mouse clicked place object in that position, and then use PositionX and PositionY to remember where you left it"
Usually on scrolling backgrounds, all other objects are placed by the programmer, and so all that matters is that the objects move with the background.
However, I'm trying to work out how do the objects move with the background whilst staying in their positions? (So that trees don't knock fences over whilst the player is scrolling for example.) I've already started using the code, but as you can see it doesn't work properly, see if you can sort it out:
http://scratch.mit.edu/projects/Borrego6165/1976590
Offline
No, this is different. Usually, a fixed object is easy to code because a code can be written to make it stay in front of the same spot on the background no matter what. However, I need a code that has a variable where no matter where the player puts a house (for example) on the ground, it will saty in that position whilst not crashing into trees and skyscrapers!!!
See my example on the post above.
Offline
Borrego6165 wrote:
No, this is different. Usually, a fixed object is easy to code because a code can be written to make it stay in front of the same spot on the background no matter what. However, I need a code that has a variable where no matter where the player puts a house (for example) on the ground, it will saty in that position whilst not crashing into trees and skyscrapers!!!
See my example on the post above.
lol, you have to do
[blocks]<set x to((( <{ scrollx }> <*> <x position> ))[/blocks]
Last edited by jslomba (2011-08-13 15:43:27)
Offline
Borrego6165 wrote:
No, this is different. Usually, a fixed object is easy to code because a code can be written to make it stay in front of the same spot on the background no matter what. However, I need a code that has a variable where no matter where the player puts a house (for example) on the ground, it will saty in that position whilst not crashing into trees and skyscrapers!!!
See my example on the post above.
Oh -- that's a bit more complicated. Just put two sprites to the sides of the object and set their ghost effect to 99. Then use one of the following examples:
If you're using velocity
Add a forever in both sprites testing whether that sprite is physically touching the house. If it is, set Xvelocity to a negative (or positive, you see which one works. it will be different for both sprites.)
If you're not using velocity
Add a forever in both sprites testing whether that sprite is physically touching the house. If it is, change Xscroll by negative the size of the player (or positive, you see which one works. it will be different for both sprites.)
That probably wasn't clear enough. If you tell me which method you use (velocity or zero acceleration) I can give you a more detailed and maybe graphical example!
Offline
Err... if only I knew the difference between velocity and acceleration
Can you tell from my build-test example?
(By the way, if you place an object around the centre of the screen it will go right under where you place it. If you try to place it near the top or bottom of the screen it'll bounce off an invisible wall!)
By the way, thanks for all trying to help, really do appreciate it. This could help in building games to make cities more expandable instead of squashed on one screen!!!
Offline
And sorry jslomba but yours didn't work somehow
By the way LS97- which is easier- volocity or acceleration? I haven't actually started the game, only test modes because I only wanted to bother if it DID work
Offline
OK sorry, I misunderstood the first post. See, samples always help! (if only I had been bothered to look the first time).
Can you explain better what you want from the project now?
Offline
Basically, i am fed up of seeing shrunken down images (like in my NowBoarding 2 game) which have been made small to fit on a small map. My goal is to make a map that can be easily explored around and also have detailed objects that have not been shrunken down because there should plenty of room for them on the map. In other words, a building game (like a city one) where you can scroll around your city instead of one fixed position. I got a zoom working as well on one test, but when you place a building down it moves positon bwtween the zoom levels
Offline
The problem is that the
doesn't just make the sprite go where you clicked it, it also offsets the position by ScrollX and ScrollY. You can cancel out this effect by changing
to
Does this help?
Oh, and by the way, add a
after
to make it work online.
Last edited by floppy_gunk (2011-08-14 01:22:42)
Offline
Borrego6165 wrote:
Basically, i am fed up of seeing shrunken down images (like in my NowBoarding 2 game) which have been made small to fit on a small map. My goal is to make a map that can be easily explored around and also have detailed objects that have not been shrunken down because there should plenty of room for them on the map. In other words, a building game (like a city one) where you can scroll around your city instead of one fixed position. I got a zoom working as well on one test, but when you place a building down it moves positon bwtween the zoom levels
![]()
Ah, really cool project! Very complicated though and probably not so obvious to explain in words. You did a great job already with that stuff, so what I would suggest is brainstorming. Think about what you're trying to do in English, then translate it into Scratch blocks. I've tried it in many other languages too, it makes programming so much easier!
Offline
Thanks floppy_gunk and LS97! I'll try to brainstorm for a bit. Also, whats the difference between acceleration and velocity?
Offline
By the way, I'm goanna get straight onto designing the city game!!! Thanks soo much. If there are any requests for the game (like avenues or special landmarks) then please tell me!
Offline
I'll put all my questions onto here so you don't have to scroll up:
1. Difference between zero acceleration and velocity?
2. Now that I know the full code, there is one problem. I know now that if you constantly clear and redraw stamps on screen constantly then they'll go into the coreect positions. However, in a city you need more than road, but when a stamp is placed (e.g. 10,10) the variables are PositionX 10 and PositionY 10, but when you place a new stamp at say 20,15, not only does the new stamp go to 20,15, but the old one does too because the variable has changed to PositionX 20 and PositionY 15. I'm trying new ways to over come this.
Offline
Borrego6165 wrote:
1. Difference between zero acceleration and velocity?
One's got velocity, one hasn't
Here's an example. When moving sideways, the player works like a car. Starts at 0mph and slowly goes up to 100mph, but going through 20mph, 40mph, etc. But when going up/down, it bounces from 0mph to 100mph without going through 20 and 40.
____________________________________________________________
Borrego6165 wrote:
2. I know now that if you constantly clear and redraw stamps on screen constantly then they'll go into the coreect positions. However, in a city you need more than road, but when a stamp is placed (e.g. 10,10) the variables are PositionX 10 and PositionY 10, but when you place a new stamp at say 20,15, not only does the new stamp go to 20,15, but the old one does too because the variable has changed to PositionX 20 and PositionY 15. I'm trying new ways to over come this.
You could try putting all of this into three lists: object, X, and Y. Here's what a complex city would look like:
object_____X______Y road | 43 | -100 road | 63 | -100 house | 176 | 40 garage | 214 | 7 bridge | -6 | 84
Then, when stamping, you could read the lists and stamp according to position in list + the scroll position.
Be aware though, that lists slow down the project a lot! I didn't consider speed in this, so it might be very laggy on big cities.
Offline
thanks, but I'm using this gopher scratch now, and they're developing this clone tool (which is a stamp but with its own script) so if it doesn't work properly then i'll use the list method
Offline
Borrego6165 wrote:
thanks, but I'm using this gopher scratch now, and they're developing this clone tool (which is a stamp but with its own script) so if it doesn't work properly then i'll use the list method
Oh, OK! I thought you were using Scratch. Good luck, and why not upload it to Mod Share once it's done?
Offline
I were using scratch, but i decided to switch. and yeah i will upload it
Offline
Woah, this were ages ago. When the city game seemed impossible, and now look at it, hehe. By the way, whens your site goanna be back on?
Offline