Weird stuff happening with keypress script

Ask and answer questions about making games and related topics. Unrelated topics go in that other forum.

Moderators: marionline, SDHawk

Post Reply
User avatar
TheMan
Red Slime
Posts: 31
Joined: Wed Jul 05, 2017 8:42 pm

Weird stuff happening with keypress script

Post by TheMan »

Basically I've set up a script for this pac-man game in which the camera only moves up and down, not left and right. the normal camera movement is suspended and this script is used as a keypress script.

Code: Select all

 
 if ((key is pressed (key: up)) == TRUE) then, begin
      focus camera (7, hero y, 4)
  end
  if ((key is pressed (key: down)) == TRUE) then, begin
      focus camera (7, hero y, 4)
  end
(note: the "7" is just the center of the screen in tiles)

in the gif to the right you can see that when i take a step up, the script triggers instantly, moving the camera at about the same speed as the sprite. but when i take a step down, the script only triggers after i've completed the walking animation for one step, resulting in the camera lagging behind. Although the commands are exactly the same (besides the direction), there is still a glaring difference in output. is this fixable or should i use a different setup entirely?
Attachments
PAC-MAN0000.gif
PAC-MAN0000.gif (192.19 KiB) Viewed 1363 times
User avatar
Bob the Hamster
Lord of the Slimes
Posts: 7658
Joined: Tue Oct 16, 2007 2:34 pm
Location: Hamster Republic (Ontario Enclave)
Contact:

Post by Bob the Hamster »

I think this is a side effect of the fact that a hero's position is determined by the top left corner of the 20x20 space that they occupy, rather than the center.

I think you will have better luck with the command that positions the camera by pixels, and the command that gets hero position in pixels

You can apply the camera position every tick rather than just when the keys are pressed
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

It looks like the map is the same width as the screen, so why do you need to script camera movement anyway? You want the camera to lag the player position?

If you want it to lag one tile behind, you could use an 'each step' script instead, that way it will only trigger at the end of each 20 pixels of player movement.
User avatar
TheMan
Red Slime
Posts: 31
Joined: Wed Jul 05, 2017 8:42 pm

Post by TheMan »

Bob the Hamster wrote:I think you will have better luck with the command that positions the camera by pixels, and the command that gets hero position in pixels
thanks, this worked like a charm

@TMC it's a wrapping map, as to let the player go through the pipes smoothly
TMC
Metal King Slime
Posts: 4308
Joined: Sun Apr 10, 2011 9:19 am

Post by TMC »

:/ I should have realised that!
Post Reply