How To Make The Screen Shake (Version 4.1.5)

Bucket Mouse

Active member
Thanks to Mr. Granato for pointing me in the right direction to find the solution to this....
UPDATED 5-24-2020 to fix a bug that prevented the sprites from showing during the shaking process

Make three variables, shakeOn, XScrollNo and shakeCycle, before using.
Then open HandleScreenLoads.asm and add this right below the opening line. The notes in the code describe how it works.

Code:
	;;;;; THIS MATERIAL ADDED TO SHAKE THE SCREEN ON COMMAND
	
	LDA shakeOn
	CMP #$01
	BNE shakeskipper
	
	shake:
	INC xScroll
	INC XScrollNo ; variable counting the current number of pixels away from the norm
	JSR WaitFrame
	LDA #$04 ; this means it will shake four pixels...change the number to what you desire
	CMP XScrollNo
	BEQ shakeBack
	JMP shake

	shakeBack:
	DEC xScroll
	DEC XScrollNo
	JSR WaitFrame
	LDA #$00
	CMP XScrollNo
	BEQ shakeOver
	JMP shakeBack

	shakeOver:
	INC shakeCycle ; variable for number of vibrations in sequence
	LDA shakeCycle
	CMP #$04 ; stops shaking after four vibrations...change the number to what you desire
	BNE shake
	LDA #$00
	STA shakeCycle ; resets the shake cycle so you can use it again elsewhere
	STA shakeOn

shakeskipper:

;;; END OF ADDED MATERIAL

Now you'll need a trigger to make the screen shake when you want it to. So create a file called shaketrigger.asm that contains just these two lines:

Code:
	LDA #$01
	STA shakeOn

This code shakes the screen horizontally. To shake it vertically, change "xScroll" to "yScroll"

You cannot move your character while the screen shakes. Any sprites on screen will also be stationary. This is just how screen shake works on 8-bit (I distinctly remember Link's Awakening screen shakes working like this).

Au naturel, it works as a button press and as a monster AI option (which makes it perfect for cutscenes). But if you want to add the effect to a tile, the screen will shake endlessly because your sprite is perpetually on it. You will have to add a fourth variable, shakeOff. You would put this before everything else in the script:

Code:
	LDA shakeOff
	CMP #$01
	BEQ shakeReallyOver
	INC shakeOff

Then add
shakeReallyOver:
at the end.

This will prevent the screen shake from looping again. Though you will have to reset shakeOff back to zero if you want to use the same tile somewhere else.
 

dale_coop

Moderator
Staff member
Nice script, thank Bucket Mouse for sharing it :)
I guess it would work only with xScroll (as currently, there is no vertical scrolling in NESmaker)...?
 

baardbi

Well-known member
This is so awesome. I will definately make use of this. Thank you so much for sharing :)
 

Dirk

Member
dale_coop said:
Nice script, thank Bucket Mouse for sharing it :)
I guess it would work only with xScroll (as currently, there is no vertical scrolling in NESmaker)...?

I was wondering too. I mean, I could simply try it out myself, but I don't have access to NESmaker the next few days.
 

Dirk

Member
Thank you! That's awesome!

Now I only have to find a reason why my screen would need to shake XD
 

slumpitydump

New member
So I added and defined the script but when I go to export and test, it says that there is an unknown label, and it seems the unknown label is xScroll.
Is xScroll a zero page variable? I'm using Dale's 2 player platformer module? Do yall think this is compatible with that or would I have to use the base platformer module?
 

Bucket Mouse

Active member
Yeah, obviously xScroll has to be in the code to begin with. For what it's worth I used the Adventure module to test it, so it doesn't have to be the (unaltered) Platformer module specifically. It just can't be a radically modified one like Dale's.
 
I got everything hooked up, the game compiles. now this is the odd part. I have this set up as a AI script with the variables. But once the action starts my Enemy object shakes and the causes the player object to start auto scrolling
 

dale_coop

Moderator
Staff member
It's because the user variables need to be set to "0" (and not "4", in your "Project Settings > User Variables").
 
dale_coop said:
It's because the user variables need to be set to "0" (and not "4", in your "Project Settings > User Variables").

One i put the Var at Zero i get unknown labels on
3, 6, 12, 15, 20, 21, and 25.
 
So I set the variables at a number 2 and now the screen does shake but I still have some other glitches and going on with the background graphics. I now have this set up as a input instead of an AI action which I would prefer to be able to use an AI action on a boss fight but I still have the problem with it wanting to auto scroll to the right so I'm trying to add a couple plus signs to my controller script to see if that works
 
So as input scripts go I can get the screen shake to work without a problem now except for the fact when I 1st hit the input button it seems to work me around to different screens until it lands on one that it likes and then I can hit the select button which ever button the input is attached to and it works great but it's just it has to warp out 1st so how do i stop that
 
So I got it working in the platform module as an AI action and it works pretty cool stuff anybody's intrested let me know and I can post up what I did to make it work
 

Bucket Mouse

Active member
What did you do? I didn't understand where your errors were coming from since for me, using it as an AI works flawlessly from the beginning. You shouldn't be getting Unknown Label messages just because you set your variables to zero -- that doesn't make any sense. They're supposed to be at zero; their values are set in the code itself -- if you want more or less shakes, you change the code numbers where marked.

So maybe your graphics glitches were due to setting your variables at 2. What did they look like?

Edit: Oh, wait....were you using the Platform module the whole time? I never tested it on that.
What did you do to make it work on Platform?
 
Bucket Mouse said:
What did you do? I didn't understand where your errors were coming from since for me, using it as an AI works flawlessly from the beginning. You shouldn't be getting Unknown Label messages just because you set your variables to zero -- that doesn't make any sense. They're supposed to be at zero; their values are set in the code itself -- if you want more or less shakes, you change the code numbers where marked.

So maybe your graphics glitches were due to setting your variables at 2. What did they look like?

Edit: Oh, wait....were you using the Platform module the whole time? I never tested it on that.
What did you do to make it work on Platform?

First off thank you for creating this code. I did the same thing in the platform module
 

Attachments

  • Shake screen1 AI.GIF
    Shake screen1 AI.GIF
    142.2 KB · Views: 2,871
  • shake screen 2.GIF
    shake screen 2.GIF
    17.1 KB · Views: 2,869
  • Shake Action step 2.GIF
    Shake Action step 2.GIF
    21.5 KB · Views: 2,870
Top Bottom