This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2013-01-19 12:57:07

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Help with enemies in scrolling

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  smile


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#2 2013-01-19 13:00:57

iaoumeur
Scratcher
Registered: 2012-11-24
Posts: 500+

Re: Help with enemies in scrolling

You can just make them endlessly glide... Like the red squares in my project.
Hope this helps!


The Dot 3 is out!!! Play it here!

Offline

 

#3 2013-01-19 13:14:23

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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)

Now, whenever you want your enemies to move, just change ScrollX* and you're done! For example, this'll make your enemy move right:

repeat (60)
 change [ScrollX* v] by (2)
end

I hope that this helps!


http://i46.tinypic.com/35ismmc.png

Offline

 

#4 2013-01-19 13:22:10

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

Thanks... but I need a way to set their x position in a scrolling game though...
But I like your game  smile


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#5 2013-01-19 13:29:50

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

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?  smile


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#6 2013-01-19 13:49:48

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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?  smile

Well, yes, I do. Just use this simple script:

when gf clicked
forever
 if <<(ScrollX) > (240)> or <(ScrollX) < (720)>>
  show
 else
  hide
 end

Just to say, some tweaking might be needed. Oh, and you don't bother me at all, so you're fine. ;)


http://i46.tinypic.com/35ismmc.png

Offline

 

#7 2013-01-19 15:03:37

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

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!


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#8 2013-01-19 16:12:54

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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

Now onto your moving enemy; I think that's more of an issue with the scripts that you used; could you show them? Just to say, if you ever want to learn how to make scratchblocks in the forums, you could go here.

Last edited by ErnieParke (2013-01-19 16:16:28)


http://i46.tinypic.com/35ismmc.png

Offline

 

#9 2013-01-19 16:39:50

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

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
end


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#10 2013-01-19 17:57:41

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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)


http://i46.tinypic.com/35ismmc.png

Offline

 

#11 2013-01-20 09:33:34

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

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


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#12 2013-01-20 12:01:58

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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.


http://i46.tinypic.com/35ismmc.png

Offline

 

#13 2013-01-20 16:36:50

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

Yes, I tweaked it. It doesn't seem to wok though...


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#14 2013-01-20 16:39:52

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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
 end

Just 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


http://i46.tinypic.com/35ismmc.png

Offline

 

#15 2013-01-21 09:41:50

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

It still doesn't seem to be working, the sprite just never shows at all. Am I doing something wrong?


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#16 2013-01-21 09:51:59

bonechill
Scratcher
Registered: 2012-05-02
Posts: 500+

Re: Help with enemies in scrolling


http://www.planetminecraft.com/files/sigs/scratch9p_693826_sig.jpg

Offline

 

#17 2013-01-21 12:00:35

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

Thanks, but how would that work while the enemy moves?


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#18 2013-01-21 13:35:07

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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.


http://i46.tinypic.com/35ismmc.png

Offline

 

#19 2013-01-21 14:12:44

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

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


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#20 2013-01-21 14:24:59

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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)


http://i46.tinypic.com/35ismmc.png

Offline

 

#21 2013-01-21 14:39:52

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

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...  sad


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#22 2013-01-21 14:51:28

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

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
 end

It still isn't working...  sad

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)


http://i46.tinypic.com/35ismmc.png

Offline

 

#23 2013-01-21 15:12:43

Mileaz
Scratcher
Registered: 2012-11-30
Posts: 31

Re: Help with enemies in scrolling

Wonderful! It works! Thank you very, very, very much!  big_smile

(ErnieParke is awesome!)


http://mag.racked.eu/cimage/i9002/Achievement++get%21/Stalker%21/mca.png

Offline

 

#24 2013-01-21 15:33:13

ErnieParke
Scratcher
Registered: 2010-12-03
Posts: 1000+

Re: Help with enemies in scrolling

Mileaz wrote:

Wonderful! It works! Thank you very, very, very much!  big_smile

(ErnieParke is awesome!)

You're welcome! Also, good luck with your game!

Last edited by ErnieParke (2013-01-21 15:33:32)


http://i46.tinypic.com/35ismmc.png

Offline

 

Board footer