dMZX Forums: Is there an easy method to scroll overlay and board separately? - dMZX Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Is there an easy method to scroll overlay and board separately?

#1 User is offline   darkhog 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 40
  • Joined: 20-November 12
  • Gender:Male

Posted 21 November 2012 - 02:39 PM

The reason for this is that I'd like to make nice parallax effect (not for Ultraracer, though as my skills are yet too limited to tackle this project). So is it possible to scroll overlay separately to main game area?

Title fixed as per request.
There are no impossible things, there is only lack of skills.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
~-+=SMZXDraw! The ultimate tool for editing charsets and palettes for SMZX games - FEEDBACK NEEDED!!!=+-~
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Society consists mostly of jerks. We cannot neglect their involvement into building our civilization - without them we
wouldn't have such wonderful inventions like war, money, drugs... or Microsoft Windows.
0

#2 User is offline   Risu2112 

  • I can't get the top off this bottle
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,864
  • Joined: 12-August 01
  • Gender:Male

Posted 21 November 2012 - 03:10 PM

When you scroll the board, what's actually happening is that the viewport is moving around, so no the overlay and board cannot be "scrolled" independently.

What you could do to simulate this fairly easily is use the copy overlay block command.

Quote

COPY BLOCK # # # # # #
COPY OVERLAY BLOCK # # # # # #
Copies a block of things from one location on the board or overlay to another section. The first two numbers state the upper-left corner of the block to be copied, the second two numbers state the size of the block, and the third two numbers state the destination block's upper-left corner.

This code will copy an overlay block at "SourceX" "SourceY" of the size "Height" by "Width" to the location "SourceX"+1, "SourceY"), and paste it one character to the eat of where it was. Keep in mind it will not remove the existing overlay (the left most column would now be doubled up in this case) You can get around this by using a second copy overlay block to copy a blank section of overlay over the leftover part. (it's a copy command, not a cut command).

(All of these counters are user defined and can be replaced by anything you want.)
copy overlay block at "SourceX" "SourceY" by "Width" "Height" to "('SourceX'+1)"  "SourceY"


Alternatively you could use a second copy block to grab the overrun section, assuming it hasn't gone off of the board, and wrap it back around.
copy overlay block at "SourceX" "SourceY" by "Width" "Height" to "('SourceX'+1)"  "SourceY"
copy overlay block at "('SourceX'+1)" "SourceY" by 1 "Height" to "SourceX" "SourceY"


In this example the first command copies the entire block, and pastes it 1 character to the east, it then copies the overrun section back to the start. There are much more advanced and fancy ways you can set this sort of thing up depending on what specifically you need.

This post has been edited by Risu2112: 21 November 2012 - 03:15 PM

Respond! Vibrate! Feed back! Resonate!
<Cybersilver> "All my sugestions are for FUTER VERSIONS. Say it with me Fu-ter futer. Yep..."
9-21-2009, SFMZX game play video: HERE
Risu2112
0

#3 User is offline   darkhog 

  • Newbie
  • Pip
  • Group: Members
  • Posts: 40
  • Joined: 20-November 12
  • Gender:Male

Posted 21 November 2012 - 03:16 PM

Thanks, Risu. Too bad there isn't easy way to do this (I've considered using method like yours, but figured I'd ask on the forums in case there is any better). Oh, well. Is there any routine you can think of that will fill rectangle on overlay with spaces that is fast enough to be executed every frame?
There are no impossible things, there is only lack of skills.
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
~-+=SMZXDraw! The ultimate tool for editing charsets and palettes for SMZX games - FEEDBACK NEEDED!!!=+-~
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Society consists mostly of jerks. We cannot neglect their involvement into building our civilization - without them we
wouldn't have such wonderful inventions like war, money, drugs... or Microsoft Windows.
0

#4 User is offline   Risu2112 

  • I can't get the top off this bottle
  • PipPipPipPipPip
  • Group: Members
  • Posts: 1,864
  • Joined: 12-August 01
  • Gender:Male

Posted 21 November 2012 - 03:23 PM

View Postdarkhog, on 21 November 2012 - 07:16 AM, said:

Thanks, Risu. Too bad there isn't easy way to do this (I've considered using method like yours, but figured I'd ask on the forums in case there is any better). Oh, well. Is there any routine you can think of that will fill rectangle on overlay with spaces that is fast enough to be executed every frame?


Have you considered reserving a big rectangle of empty overlay space on your board some where? If so you could copy overlay block from that location to what you want cleared. That would be the easiest and fairly cheap way to do it.
Respond! Vibrate! Feed back! Resonate!
<Cybersilver> "All my sugestions are for FUTER VERSIONS. Say it with me Fu-ter futer. Yep..."
9-21-2009, SFMZX game play video: HERE
Risu2112
0

#5 User is offline   Old-Sckool 

  • megazeux breaker
  • PipPipPipPip
  • Group: Members
  • Posts: 649
  • Joined: 07-June 05
  • Gender:Male

Posted 23 November 2012 - 04:29 AM

You could also probably use sprites to achieve what you want. Sprites are basically additional overlays; just define the x,y region of the board/vlayer you want to display, set a width, place it. Sprites can be a little tricky to work with though since you have to initialize them properly, manage draw order somewhat, and have to turn them off somehow when changing to a board that no longer need them (since they're global).

One of the only good wiki pages is on sprites. You should read up on 'm. http://www.digitalmz...p?title=Sprites
<Nadir> mzxers don't make GAMES, usually
<phthalocyanine> they make experiences.
<Nadir> demos, more like
<Nadir> a glimpse into what could have been if mzx wasn't such a bore to work with
<Nadir> actually, i'm being unfair
<Nadir> i would have made mzx games if it was capable of running on more than 20 computers worldwide in 1998
<Nadir> >:D

<%Alice> functor
<%nooodl> i hear C++ has a thing called functors and they're completely different from Haskell functors...
<rorirover> the result is the most horrid thing in C++, it's basically black magic and it transforms any code you're writing into some eldritch monstrosity
1

#6 User is offline   Lachesis 

  • the pinnacle of human emotion
  • Group: DigiStaff
  • Posts: 3,895
  • Joined: 17-July 04
  • Gender:Female
  • Location:Sealand

Posted 23 November 2012 - 05:25 PM

As far as doing what you're trying to do, I'd suggest buffering your entire overlay on the vlayer and using a static sprite to display it, like Old-Sckool suggested.

. "you only have to set one dimension but I like to set both for clarity of reading the code later"
: "justentered"
set "vlayer_width" 100
set "vlayer_height" 100
set "vlayer_size" "(100*100)"
. "we're only doing this once per board load so it's ok. 'p02' means vlayer.  The @ sign is mandatory for identifying this as a file load and isn't a part of the file name"
put "@my_overlay.mzm" image_file p02 0 0


. "the SPRn counters use decimal for n, the sprite number"
set "SPR0_VLAYER" 1
. "this places the sprite relative to the viewport visually.  The collision box is still absolute, however, so don't use collision with static sprites."
set "SPR0_STATIC" 1
: "loop"
. "SCROLLEDX, SCROLLEDY -- the position of the top-left corner of the viewport on the board"
set "SPR0_REFX" "('SCROLLEDX'/2)"
set "SPR0_REFY" "('SCROLLEDY'/2)"
. "c?? -- if this is any color other than c??, every char of the sprite will be that color.  Otherwise, it will use the colors of the source chars."
. "p00 -- the sprite number we want to put in hex"
put c?? sprite p00 0 0
wait 1
goto "loop"


Since this also came up, I'd like to cover clearing the overlay:

Don't put a big block of empty space on your board or in the vlayer. When you try to copy it to the overlay, it won't work, because copy blocks across layers ignore char 32s. Here's a good way to clear the overlay that doesn't require a buffer either from another part of the overlay (waste of board space, will slow down processing if the board gets big enough, but could work if you're using a static overlay) or from an MZM (file access, slower, ugh):

: "#CLEAR"
put c00 ' ' overlay 0 0
loop start
copy overlay block 0 0 "(2^'LOOPCOUNT')" 1 "(2^'LOOPCOUNT')" 0
loop "((2^('LOOPCOUNT'+1)<'BOARD_W')*10000)"
loop start
copy overlay block 0 0 "BOARD_W" "(2^'LOOPCOUNT')" 0 "(2^'LOOPCOUNT')"
loop "((2^('LOOPCOUNT'+1)<'BOARD_H')*10000)"
goto "#RETURN"


I'm sure you get what it's doing, but just in case, I'll explain it. We're copying exponentially growing blocks of blank space to wipe as much space as possible in as few cycles using a loop N trick: the loop N command evaluates its input every time it is passed and checks to see if LOOPCOUNT is equal to that number. If it isn't, it increments LOOPCOUNT and goes back to loop start. Here, we use a conditional that will make it loop for a good while until it hits the right board edge, then it works in the other direction until it hits the bottom edge. This is more efficient than manually incrementing a counter and doing a check yourself.

This is a good time to note that MZX expressions don't follow an order of operations. They evaluate purely from left to right.
"Let's just say I'm a GOOD hacker, AND virus maker. I'm sure you wouldn't like to pay for another PC would you?"

xx̊y (OST) - HELLQUEST (OST) - Zeux I: Labyrinth of Zeux (OST) (DOS OST)
w/ Lancer-X and/or asgromo: Pandora's Gate - Thanatos Insignia - no True(n) - For Elise OST
MegaZeux: Online Help File - Keycode Guide - Joystick Guide - Official GIT Repository
1

#7 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 16 January 2013 - 07:52 PM

Greetings darkhog, hopefully you've found a solution to your problem. I am working on a game now that is entirely sprite based, even the background, foreground and level itself. That was the solution I came up with to get around the parallax problem.

It's 2d sidescrolling, so the player sprite is interacting with the blocks in the level, but the background sprite is displayed above the level. The level sprite is referenced to the players sprite and moves with him. So the program is projecting the blocks that are under the background, to above it. Thus, parallax because these two layers may move independently, and one appears in front of the other. I also have another sprite on top of that, acting as the foreground. It's number is quite high, like 240 something, so it appears above everything accept a few menus and the pause icon.

Sprite & vlayer management is done through establishing sprites that are used throughout the game, on a special board that is laid out like the vlayer, a physical representation. Then sprites that are specific to only one board are set and cleared on entering and leaving that board. Those use a specific range of numbers, so they don't overwrite any of the full game sprites. Hope this helps if you're still looking for a solution. Let me know if you need more info.
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

#8 User is offline   Graham 

  • . "@Master Procrastinator"
  • PipPipPipPip
  • Group: Members
  • Posts: 625
  • Joined: 28-December 12
  • Gender:Male
  • Location:Oregon

Posted 17 January 2013 - 02:59 AM

I hope that made sense the way I explained it. What I forgot to mention was that you have to visualize the sprites like flat sheets of paper laying in a stack, the board is at the bottom, with sprites 0-255 stacked on it going up in that order. The overlay is on top of everything. The overlay didn't work with my sprite system, so I only use it for transferring some menu option information.
Currently working on Servo for MegaZeux, I hope to complete it by the middle of 2015? Who knows...

"Before you criticize someone, you should walk a mile in their shoes. That way, when you criticize them, you’re a mile away and you have their shoes."
-Jack Handey
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users