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

#1 2009-02-14 15:21:53

jwiens
Scratcher
Registered: 2007-10-17
Posts: 39

moving sprite within scrolling background

i am making a game where you can scroll the background with your mouse. i have a problem with the units you create and them moving within the variable scroll x. if anyone can help it would be much appreciated. this game is my attempt at the flash game age of war if you don't understand what i am talking about

Offline

 

#2 2009-02-15 05:16:44

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: moving sprite within scrolling background

work with something like
ScrollX = (mousex*2)
ScrollY = (mousey*2)

Offline

 

#3 2009-02-17 23:43:22

blahdeblah
Scratcher
Registered: 2008-02-19
Posts: 45

Re: moving sprite within scrolling background

oh i see what you mean
Use a script like:
When green flagged clicked,
Forever:
If mouse x > 240,
Change scroll x by -4 (or some number)
If mouse x < - 240
Change scroll x by 4 (or some number)

And create a separate script for the terrain, one with the script, forever set x to scroll x, and the other(s) to set x to scroll x + 480, with other terrain sprites adding 480 each time.

Offline

 

#4 2009-02-19 16:15:15

jwiens
Scratcher
Registered: 2007-10-17
Posts: 39

Re: moving sprite within scrolling background

no, i already made it scroll, i am trying to make the units set in a certain area of the scroll variable and constantly change their position unless they are fighting, thanks anyway

Offline

 

#5 2009-05-16 12:52:44

gabrielgabriel
Scratcher
Registered: 2009-04-12
Posts: 52

Re: moving sprite within scrolling background

How to use ScrollY?????????

Offline

 

#6 2009-05-18 13:44:30

yambanshee
Scratcher
Registered: 2007-11-06
Posts: 500+

Re: moving sprite within scrolling background

gabrielgabriel wrote:

How to use ScrollY?????????

same as scroll x but with 360 instead of 480. Also please don't hijack other threads.

Offline

 

#7 2009-05-18 14:58:52

justbanana
Scratcher
Registered: 2009-05-06
Posts: 16

Re: moving sprite within scrolling background

Oh, like a td or something with a huge screen that can't all be seen at once. Here's one way:
You make 2 variables for each unit: xmove and ymove. Also scrolX and scrollY for scrolling
Use it in the same way you would make terrain sprites in a scroller. Example:
When start clicked
Set xmove to -700
Set ymove to 0
Forever-
Set Xposition to scrollX+xmove
Set Yposition to scrollY+ymove

Movement example(arrow keys)
when start clicked
forever-
If right arrow pressed
Change xmove by -10
If left arrow pressed
change xmove by 10
If up arrow pressed
change ymove by -10
if down arrow pressed
change ymove by 10
************************************************************************************************************
Basically, along with the script you already have, this will get you a guy on the far right that you scroll to get to. Then you can move him with the arrow keys. You can change the movement into something like when you select the thing, then click change x and y by a multiple of it's speed until you get close to the selected area. Good luck!  smile

Offline

 

Board footer