Could anyone please help me with how to add moving enemies into a scrolling game? I can't figure out how to coordinate the scroll x position with the x position.
The project so far: http://scratch.mit.edu/projects/Mileaz/3047823
Thanks in advance! Mileaz
Offline
You can just make them endlessly glide... Like the red squares in my project.
Hope this helps!
Offline
Well what a coincidence; I was looking at New Projects and saw your project, then I went into the Help with Scripts forum to help how ever needed help, and found your project again.
Anyway, one way you could do this is by having your sprites each have a new variable called ScrollX*. Then, to make the enemies scrolling, use this script:
when gf clicked set [scrollx* v] to (0) forever go to x: (((ScrollX) + (ScrollX*)) + (480)) y: (-75)
repeat (60) change [ScrollX* v] by (2) end
Offline
Wow! Thank you ever so much ErnieParke! It works brilliantly! I hate to bother you again, but do you know how I could make the enemy sprite invisible when it goes out of range instead of just being half on the screen?
Offline
Mileaz wrote:
Wow! Thank you ever so much ErnieParke! It works brilliantly! I hate to bother you again, but do you know how I could make the enemy sprite invisible when it goes out of range instead of just being half on the screen?
Well, yes, I do. Just use this simple script:
when gf clicked forever if <<(ScrollX) > (240)> or <(ScrollX) < (720)>> show else hide end
Offline
Thankyou again! However I'm having a few problems with making my enemy move however as it just seems to randomly jump around?
Also would you mind helping me out with how to make the hide/show thing work with a moving sprite?
Thanks so much! Sorry for my nooby-ness!
Offline
Mileaz wrote:
Thankyou again! However I'm having a few problems with making my enemy move however as it just seems to randomly jump around?
Also would you mind helping me out with how to make the hide/show thing work with a moving sprite?
Thanks so much! Sorry for my nooby-ness!
Ah yes, I forgot that you might be needing that script for moving sprites. All you'll need to do is make a small change:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (240)> or <((ScrollX) + (ScrollX*)) < (720)>> show else hide end
Last edited by ErnieParke (2013-01-19 16:16:28)
Offline
Mileaz wrote:
This is my script for the enemy:
When gf clicked Set [scroll* v] to (0) forever go to x: <<(scrollx)+(scrollx*)>+(1200)> y: (-124) repeat (60) change[scroll* v] by (2) end
Ahhh...Okay; I see the problem. The go to block has to have it's own script, or else it'll only run whenever the repeat loop ends, which you don't want. So what you'll have to do is separate what you do have until it looks like this:
When gf clicked Set [scroll* v] to (0) forever go to x: <<(scrollx)+(scrollx*)>+(1200)> y: (-124)
when gf clicked forever repeat (60) change[scroll* v] by (2) end
Last edited by ErnieParke (2013-01-19 17:57:52)
Offline
Thanks, I also can't get this to work?
ErnieParke wrote:
Ah yes, I forgot that you might be needing that script for moving sprites. All you'll need to do is make a small change:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (240)> or <((ScrollX) + (ScrollX*)) < (720)>> show else hide end
Offline
Mileaz wrote:
Thanks, I also can't get this to work?
ErnieParke wrote:
Ah yes, I forgot that you might be needing that script for moving sprites. All you'll need to do is make a small change:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (240)> or <((ScrollX) + (ScrollX*)) < (720)>> show else hide end
Just to make sure, did you tweak the code? The 240&720 need to be changed to 960&1440, respectively.
Offline
ErnieParke wrote:
Mileaz wrote:
Thanks, I also can't get this to work?
ErnieParke wrote:
Ah yes, I forgot that you might be needing that script for moving sprites. All you'll need to do is make a small change:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (240)> or <((ScrollX) + (ScrollX*)) < (720)>> show else hide endJust to make sure, did you tweak the code? The 240&720 need to be changed to 960&1440, respectively.
Ohhh...My mistake. I just realised that the "or" needs to be changed to an "and" So, what you actually need is:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (960)> and <((ScrollX) + (ScrollX*)) < (1440)>> show else hide end
Offline
Offline
Mileaz wrote:
Thanks, but how would that work while the enemy moves?
Well then could I look at your code, or could you quickly upload your project? It's most likely hidden in there.
Offline
ErnieParke wrote:
Mileaz wrote:
Thanks, but how would that work while the enemy moves?
Well then could I look at your code, or could you quickly upload your project? It's most likely hidden in there.
Sure, here's the link: http://scratch.mit.edu/projects/Mileaz/3051808
Offline
Mileaz wrote:
ErnieParke wrote:
Mileaz wrote:
Thanks, but how would that work while the enemy moves?
Well then could I look at your code, or could you quickly upload your project? It's most likely hidden in there.
Sure, here's the link: http://scratch.mit.edu/projects/Mileaz/3051808
Oh, so it's part of how you made your scrolling game. Hopefully, if I'm correct, then this is the needed script:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (-960)> and <((ScrollX) + (ScrollX*)) < (-1440)>>//Note values. show else hide end
Last edited by ErnieParke (2013-01-21 14:25:06)
Offline
ErnieParke wrote:
Oh, so it's part of how you made your scrolling game. Hopefully, if I'm correct, then this is the needed script:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (-960)> and <((ScrollX) + (ScrollX*)) < (-1440)>>//Note values. show else hide end
It still isn't working...
Offline
Mileaz wrote:
ErnieParke wrote:
Oh, so it's part of how you made your scrolling game. Hopefully, if I'm correct, then this is the needed script:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) > (-960)> and <((ScrollX) + (ScrollX*)) < (-1440)>>//Note values. show else hide endIt still isn't working...
Ahhh... I need to work with scrolling games a bit more nowadays. Anyway, hopefully this is the lsat change, and if my tests somehow didn't go wrong in some strange way, then this is what you need:
when gf clicked forever if <<((ScrollX) +(ScrollX*)) < (-960)> and <((ScrollX) + (ScrollX*)) > (-1440)>>//Note <'s. show else hide end
Last edited by ErnieParke (2013-01-21 14:51:50)
Offline
Mileaz wrote:
Wonderful! It works! Thank you very, very, very much!
(ErnieParke is awesome!)
You're welcome! Also, good luck with your game!
Last edited by ErnieParke (2013-01-21 15:33:32)
Offline