• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Script Move Camera

G

Givago

Guest
Hi,

I'm new here in the forum and have a questions.

I want make my camera move with the keyboard.

But, i do no about script in game maker.

Code:
if keyboard_check_pressed('vk_left') {
    view_xview[0] -= 10;
}

if keyboard_check_pressed('vk_right') {
    view_xview[0] += 10;
}
What is wrong?
 

FrostyCat

Redemption Seeker
If you don't know about scripting, you'd be well-served consulting the Manual.

First, if you want it to keep moving while the keys are held down, use keyboard_check() instead. The description for keyboard_check_pressed() in the Manual clearly describes its one-time behaviour.

Second, get rid of the quotes around vk_left and vk_right, since they need to be treated as constants instead of strings. The example in the Manual shows no quotes around them when used with keyboard checking functions.

The next time you see something unfamiliar, don't just throw it in there hoping for the best. You've already seen for yourself how well that works. Instead, look up its entry in the Manual and follow its instructions.
 
G

Givago

Guest
I do not understand why does not work.

Code:
if keyboard_check(vk_left) {
    view_xview[0] -= 20;
}

if keyboard_check(vk_right) {
    view_xview[0] += 20;
}
by logic, I should not change the view?
why no it works?

I have called the code in the room.
 

Ralucipe

Member
sorry but i didn't understand
To put this in the nicest way possible- if you don't know what a step event is, you should definitely take a look at some beginner Drag 'n' Drop tutorials before trying to code your own GML game. There are plenty of resources out there- just do a quick Google search and you should be in business.
 
Top