How two realize an 8-dir scroll?

Blitz3D Forums/Blitz3D Programming/How two realize an 8-dir scroll?

vivaigiochi(Posted 2012) [#1]
i need 2d routine. let's say i have 4 images positioned to:

first (-500,200)
second (0,0)
third (400,400)
fourth (1600,300)

assume that screen is 800x600, we see the area from (0,0) how can scroll it?
4-dir it's ok but i need also teory..

Last edited 2012


Matty(Posted 2012) [#2]
Keep a record of an offset, eg "cornerx, cornery" - subtract the cornerx/y position from your object positions - this is the new screen coordinates.

When the view moves simply update your cornerx,cornery positions.


Midimaster(Posted 2012) [#3]
In this demo you see 4 different possibilities of scrolling the screen and moving a player too. The sample is with text commands, but it is the same with DrawImage() commands


the technic is always the same: add a offset on each drawing command:
...
Text -StartX +64*X , -StartY + 64*y,Map(X,Y)
...
Oval -StartX +PlayerX , -StartY + PlayerY , 10,10
...

here the offset variables are StartX and StartY. They have to be used negativ, because the objects need to be paint left of the 0/0 origin, to look like scrolling to the right. Negativ values will cause positiv offsets and they will be painted more right. So it looks like the scrolling goes to the left.

Now you can scroll the screen with the cursor-keys

This demonstrates how to scroll only the screen (try cursor DOWN):
If KeyDown(Key_Down) 
	StartY=StartY+1
...


If you also change the players coordinates it looks like the player keeps in the middle of the screen (try cursor RIGHT):
If KeyDown(Key_Right) 
	StartX=StartX+1
	PlayerX=PlayerX+1
...


If you add more to the player than to the screen, it looks like the player is moving fast in a scrolling screen (try cursor LEFT):
ElseIf KeyDown(Key_Left) 
	StartX=StartX-1
	PlayerX=PlayerX-2
...


And if only the player should move (and reach the screen border) use it like this (try cursor UP):
ElseIf KeyDown(Key_Up) 
	PlayerY=PlayerY-1
...


here is the complete demonstration:
Graphics 800,600
Dim Map$(30,30)
For i=0 To 29
	For j=0 To 29
		Map(i,j)= i +"/"+ j
	Next 
Next

PlayerX=800
PlayerY=800
StartX=300
StartY=300
Const Key_Left=203, Key_Right=205, Key_Down=208, Key_Up=200

Repeat
	Cls
	For X=0 To 29
		For Y=0 To 29
			Text -StartX +64*X , -StartY + 64*y,Map(X,Y)
		Next
	Next
	Oval -StartX +PlayerX , -StartY + PlayerY , 10,10
	
	If KeyDown(Key_Right) 
		StartX=StartX+1
		PlayerX=PlayerX+1
	ElseIf KeyDown(Key_Left) 
		StartX=StartX-1
		PlayerX=PlayerX-2
	EndIf

	If KeyDown(Key_Down) 
		StartY=StartY+1
	ElseIf KeyDown(Key_Up) 
		PlayerY=PlayerY-1
	EndIf
	
	Flip
Until KeyHit(Key_escape)



vivaigiochi(Posted 2012) [#4]
thanks..but i need a solution with image...hovewer thanks for little theory
it don't work well when i press up...only left right and down works well...
if i can't find a image ready solution (surely involve copyrect of image..) i will use your example to create mine and i solve for up direction :-)


Midimaster(Posted 2012) [#5]
this is not not a bug but a feature! It is what i want to demonstrate you!!! There are four different ways of coding and four different effects when scrolling!

Have a look on the effect, which is the one you need. Then change the code for the other directions the same way!

You can place DrawImage() commands instead of the Text() command. The effect is the same. Tonight, when I have more time I will code you a sample with images!


vivaigiochi(Posted 2012) [#6]
MIDIMASTER THANKS! i wait for your example..excuse if i haven't time to read well your example...i will posticipate it but soon i must read it...


Midimaster(Posted 2012) [#7]
I need more information about the reason for scrolling....

Do you want to simulate a game ground floor? Please write more about what this scrolling should be able to do! What is on the images? How big are they? What is between the images?

Do you already have this images? Can you show it?


Guy Fawkes(Posted 2012) [#8]
I could use that too :) Im trying to create a small example which demonstrates pixel-perfect collision of a player, animation of a player, scrolling of the screen like in Legend Of Zelda: A Link to the Past, a way to warp to a second map, and the loading of the level via a .dat level file created by THIS level editor: http://www.mediafire.com/?b0i5dp9i3f9qbkb

I made an example of the level editor with all the needed files. Now I just need help with the above, and problem solved! :)


Thanks, MidiMaster! :)


vivaigiochi(Posted 2012) [#9]
for thundros i can't use testlevel.bb because need global.bb. It's not present in editor.zip

for midimaster: why ask info for image? It's not important because the scroller must be indipendent of size of image..location and other...
i need an 8-dir scroll like a link to the past...


Midimaster(Posted 2012) [#10]
sorry, but I dont understand?

"a link to the past..."? my english is not very godd, what does it mean?

I dont know, why it is a probelm for you to tell me, where you will use the scroller. But it is important to know for a proper solution. There is difference between scrolling a picture in a window, when it is to big - and a scrolling like in a game.

Can you tell me, how the movement will be effected? By users keys or moving the mouse? By timer related automatic? Or depending on a player on the screen? Is it a game?

What should happen if the scrolling reaches a border of picture or world? Is there a limit?

It would make help easier, if you tell me some facts...


Guy Fawkes(Posted 2012) [#11]
vivigiochi, use test.bb bro. not testlevel.bb :)


sorry, here's the updated RAR file:


http://www.mediafire.com/?gb8wo2qgle99zio


Its from the SNES version of Legend Of Zelda:


Here's a video:


http://www.youtube.com/watch?v=OuNU4OWh0T8


Just watch a few minutes of this video to see how the maps in the overworld scroll.


Thanks to the both of u! :)


Guy Fawkes(Posted 2012) [#12]
Here's editor.bb:





Just put it in the same folder :)


Guy Fawkes(Posted 2012) [#13]
Did it work? :) Or am I missing a file?


vivaigiochi(Posted 2012) [#14]
thundros i will tell you if it work well later. thanks...

midimaster: yes the map can have limit...i'm interested how to scroll an image that is to big for screen...for mouse or keyboard it's irrilevant because change only input mode...yes it's for game but it's useful for showing large image on screen also..if it's useful thinks two (or more) image more large of screen. Obviosly there is no scroll when map stay on limit.


Guy Fawkes(Posted 2012) [#15]
I agree with Vivagiochi, although, I think there should be a demo that allows for going to other maps via a player tile to ground tile collision, as well as an example that works with the editor I posted above :)


Kryzon(Posted 2012) [#16]
I think there should be a demo that allows for going to other maps via a player tile to ground tile collision

This is totally related to game logic. It's not difficult if you break it down to clear steps.

1) When the character hits a teleportation tile, display a visual transition (fade-out, warp, shear etc.) to hide the game screen.
2) When the transition hides the screen, change the map to the new one, reposition player and reverse visual transition to bring back visibility of the game screen. The player will see the new scene fade-in, with the player already repositioned into the new map.

Each of these steps starts with an IF. "IF player hits teleportation tile...".

The visual transition is updated separately from the rest of the game. It's always running in the background, and your game engine only has to set a "hide screen" or "show screen" flag for it to change.
Most of the time this flag is set to "show screen", since the transition is hidden and the player is seeing the game happening.
Your visual transition should be updated from a function called in your main game loop, not from inside any function that checks for tile collisions or other interactions. This allows you to have characters walking and acting while the screen is fading\showing, which is more natural.


Guy Fawkes(Posted 2012) [#17]
Ok, can u at least show a way to get this to work with the level editor, and the screen scrolling when a player walks? If so, I think I can handle tile warping myself :)


Kryzon(Posted 2012) [#18]
Sorry, I don't have time right now.
In any case, you wouldn't be doing this with the editor - it should just be used to set where the teleportation tiles are placed, which map they teleport the player to and optionally what kind of visual transition to display.

The actual teleportation and transition go inside the game when it's being played.


Guy Fawkes(Posted 2012) [#19]
No, I mean to read and write the levels FOR the game

Last edited 2012


Midimaster(Posted 2012) [#20]
here is a scrolling image. You can replace the on-the-fly-simulated-image with any of your images. In this case only activate the LOADIMAGE() code line and change the file name.

Graphics 800,600

; first step: create a very large image:
  	;all this can be replaced by a LoadImage() Command 			
			LargeImage=CreateImage(800,600)
			Print "wait! creating temp. image" 
			Flip 1
			SetBuffer ImageBuffer(LargeImage)
			Color 255,255,255
			Rect 0,0,800,600
			For i=0 To 333
				Color Rand(255),Rand(255),Rand(255)
				Rect Rand(800)-100,Rand(600)-100,Rand(200),Rand(200)
			Next
			Color 255,0,0
				Rect 0,0,10,600
				Rect 790,0,10,600
				Rect 0,0,800,10
				Rect 0,590,800,10
			SmallImage=CopyImage(LargeImage)
			ScaleImage SmallIMage,0.3,0.3	
			ScaleImage LargeImage,2,2
			SetBuffer BackBuffer()
; or load an image:
	;LargeImage=LoadImage("AnyImage.png")


StartX=400
StartY=400

Const Key_Left=203, Key_Right=205, Key_Down=208, Key_Up=200, Key_Escape=1

Repeat
	DrawImage LargeImage,-StartX,-StartY	
	DrawImage SmallImage,-StartX+300,-StartY+300	
	StartX= StartX + KeyDown(Key_Right) - KeyDown(Key_Left) 
	StartY= StartY + KeyDown(Key_Down) - KeyDown(Key_Up) 
	
	If StartX<0 StartX=0
	If StartY<0 StartY=0
	If StartX>800 StartX=800
	If StartY>600 StartY=600


	Flip 1
Until KeyHit(Key_Escape)


what you can see is a 1600x1200 pix image. which you can scroll with the cursor keys. there is a second small image (400x300 pix) that follow the scrolling commands.