Revision as of 17:57, 31 March 2021 by TemplatesFTW (talk | contribs) (Automated edit: added dates to templates)

Document stub.png This article or section may not have content matching Scratch Wiki editing standards. Please improve it according to Scratch Wiki:Guidelines and Scratch Wiki:Editing Conventions. (March 2021)
Reason: First and Second person

A pen scrolling engine is simply a scrolling engine that uses the Pen Extension.

Setup

Create these variables:

(Scroll X)
(Scroll Y)
(X Vel)
(Y Vel)

Scripts

To start off, we need to create our main script.

when green flag clicked
hide
set [Scroll X v] to [0]
set [Scroll Y v] to [0]
set [X Vel v] to [0]
set [X Vel v] to [0]
forever
erase all // Reset the stage
draw stage :: custom // This will be explained later
draw player :: custom // This will be explained later
controls :: custom // This will be explained later
end

Now we need to do our control script.

define controls
change [X Vel v] by (<key (right arrow v) pressed?> - <key (left arrow v) pressed?>)
change [Y Vel v] by (<key (up arrow v) pressed?> - <key (down arrow v) pressed?>)
set [X Vel v] to ((X Vel) * [0.9])
set [Y Vel v] to ((Y Vel) * [0.9])
change [Scroll X v] by (X Vel)
change [Scroll Y v] by (Y Vel)

Now the important part, the stage.

define draw stage // make sure this is "Run Without Screen Refresh"
set pen size to (5)
set pen color to [#32a852]
go to x: [50] y: [50] with scroll :: custom
pen down
go to x: [50] y: [-50] with scroll :: custom
go to x: [-50] y: [-50] with scroll :: custom
go to x: [-50] y: [50] with scroll :: custom
go to x: [50] y: [50] with scroll :: custom
pen up

define go to x: (x) y: (y) with scroll
go to x: ((x) - (Scroll X)) y: ((y) - (Scroll Y)

Now to draw the player

define draw player // make sure this is "Run Without Screen Refresh"
go to x: (0) y: (0)
set pen size to (40)
set pen color to [#0400ff]
pen down
pen up

Now you have a pen scrolling engine!

Cookies help us deliver our services. By using our services, you agree to our use of cookies.