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

#1 2008-04-29 20:22:21

xjediboy11
Scratcher
Registered: 2008-03-01
Posts: 5

Two way scrolling, x and y, and villains in scrolling

How do i make accurate x and y scrolling such as going to a door and seeing treasure, or walking through another door and fall into a trap or villain. This leads me to my second question. How do I get a enemy in my scroller, an example of this is in Archknight adventure. An example of two way scrolling is privateer.



xjediboy11

Offline

 

#2 2008-10-22 14:13:58

djmoomoo
Scratcher
Registered: 2007-08-31
Posts: 57

Re: Two way scrolling, x and y, and villains in scrolling

IF you look at my Zombie hunter 3.4.1 proj. That's a good exaple of scrolling.

Scrolling:

If left arrow key pressed then change enemyx by 1. This is how I would do it, by making the enemy move in the opposite direction of the player every time the player moves.
As I said earlier, check out Zombie Hunter 3..4.1!

Happy Scratching!


There are 0011 types of people, those that can count in binary and those that can't.

Offline

 

#3 2008-10-22 16:37:37

archmage
Scratcher
Registered: 2007-05-18
Posts: 1000+

Re: Two way scrolling, x and y, and villains in scrolling

When I programmed archknight's adventure this is how I made the enemies.

Since the game only moved left and right, there was only 2 variables in the script.

scrollX for controlling the position of the terrain and objects.
freeMoveX for letting the sprite move about

The code that moves the sprite was

when green flag clicked
go to x: ( scrollX+freeMoveX)

Then to made the enemies move left and right I changed the freeMoveX variable.

Like this

when green flag clicked
forever
repeat 10
change freeMoveX by 3
repeat 10
change freeMoveX by -3


If you want it to move do the same thing for sprites that move up and down you do the same thing except you use the y variable.



If you really understand how scrolling with the x coordinate works you should have no problem with scrolling the y coordinate.

Each full sized sprite is 480 units wide and 360 units tall. In order to show them side by side we space them by multiples of their width which is 480.

so if sprite 1 is moving to 480 and sprite 2 is moving to 480*2 then the sprites will appear side by side.

Since each sprite is 360 units tall to make them appear one on top of another we would change their y coordinate by their height or in this case 360.

So basically for vertical scrolling you would use this code, just put the scrollY  variable in the same way you did with the scrollX variable.

//on sprite 1
go to y: (360*1)

//on sprite 2
go to y:(360*2)

and so on.

I really recommend that you know how the codes you use work because if you don't when you get stuck you won't be able to fix your program.

Last edited by archmage (2008-10-22 16:40:49)


Hi, I am Archmage coder extraordinaire. I do Scratch,pascal,java,php,html, AS2 and AS3. Leave me a message if you want coding advice. Also check out my personal website, lots of good stuff about web development, Flash, and Scratch (v1 and v2) !

Offline

 

Board footer