Jump to content


Photo

Evil Clutches: How Do I Keep The Dragon On Screen


  • Please log in to reply
27 replies to this topic

#1 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 02:49 AM

Hi, in the Game Maker's Apprentice book, chapter 2, Evil Clutches, the dragon is moved up and down with the keyboard events. I may be overlooking it, but how can I keep the dragon from moving off the screen? If I press down he goes off the screen (and will continue). I can press up to bring him back, same up top. But how can I get the dragon to stop at the top of the screen whether I'm holding the arrow down or not? Thank you.
  • 0

#2 I*Monkey

I*Monkey

    World Class Acrobat

  • New Member
  • 161 posts

Posted 15 April 2008 - 02:54 AM

Have an invisible barrier. Very simple.
  • 0

#3 RoboBOT

RoboBOT

    GMC Member

  • Validating
  • 592 posts

Posted 15 April 2008 - 02:55 AM

You'll need to check the dragon's position before moving it.
For the up event, add an if statement (or the equivalent D&D action) checking if y>0.
For the down event, check if y<room_height
For the right event, check if x<room_width
and for the left event, check if x>0

That'll keep it in the room.

#4 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 03:07 AM

You'll need to check the dragon's position before moving it.
For the up event, add an if statement (or the equivalent D&D action) checking if y>0.
For the down event, check if y<room_height
For the right event, check if x<room_width
and for the left event, check if x>0

That'll keep it in the room.


How do I add an if statement? I'm only on chapter 2 :whistle: What does D&D mean?

Edited by johnnyLikesGames, 15 April 2008 - 03:08 AM.

  • 0

#5 RoboBOT

RoboBOT

    GMC Member

  • Validating
  • 592 posts

Posted 15 April 2008 - 03:12 AM

Sorry, that's Drag & Drop. As in, not code.
In D&D, use:
:whistle:
Fill in your variable (either x or y), the value (either 0, room_height, or room_width), and set it to "smaller than" or "greater than" appropriately. Put this right before your change in movement actions in your movement buttons events.

#6 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 03:26 AM

Sorry, that's Drag & Drop. As in, not code.
In D&D, use:
:whistle:
Fill in your variable (either x or y), the value (either 0, room_height, or room_width), and set it to "smaller than" or "greater than" appropriately. Put this right before your change in movement actions in your movement buttons events.


Trying to understand:

Just to stop the dragon from moving up too far.
var - If y is smaller than room_height, then I can move up.
move fixed up arrow.


Is that right? I ask because it didn't work.

Edited by johnnyLikesGames, 15 April 2008 - 03:26 AM.

  • 0

#7 zeldafan1107

zeldafan1107

    Quick Learner

  • New Member
  • 360 posts

Posted 15 April 2008 - 03:42 AM

Hi, in the Game Maker's Apprentice book, chapter 2, Evil Clutches, the dragon is moved up and down with the keyboard events. I may be overlooking it, but how can I keep the dragon from moving off the screen? If I press down he goes off the screen (and will continue). I can press up to bring him back, same up top. But how can I get the dragon to stop at the top of the screen whether I'm holding the arrow down or not? Thank you.


There are a few ways of going about this. One of these is creating a solid object. In the collision event with the solid object, you could have the dragon object bounce. (the solid object would NOT be visible).
OTHERWISE
You could check if outside room(other event) then reverse vertical direction(not sure if it does, but should work)
OTHERWISE
You could do this [code=auto:0]
if y > room_height
{ y = room_height}
if y < 0
{y = 0}
OTHERWISE
you could do the "if a variable has a value" Drag and drop icon. It will give you three blanks. The first being x. In that spot, just put x(this means it takes the x value of the current object), for y put room_height, and for opertation, make sure it says less than. Put this in front of your movement "code"(actions). Now you shouldnt be able to go off the bottom of the screen. HOwever, you can still go off the top. So, what you have to do, is put your movement code in a block. Thats one arrow at the top, and one arrow at the bottom(drag and drop icons). You can figure out which one is start block and which is end by hovering over it with the mouse. So it will read:

If variable has value
-Start block
-movement stuff here
-end block

Thats for your pressed down key. Your gonna do the same idea for the pressed up key except change less than to greater than and room_height to 0. That should work.
  • 0

#8 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 03:56 AM

Hi, in the Game Maker's Apprentice book, chapter 2, Evil Clutches, the dragon is moved up and down with the keyboard events. I may be overlooking it, but how can I keep the dragon from moving off the screen? If I press down he goes off the screen (and will continue). I can press up to bring him back, same up top. But how can I get the dragon to stop at the top of the screen whether I'm holding the arrow down or not? Thank you.


There are a few ways of going about this. One of these is creating a solid object. In the collision event with the solid object, you could have the dragon object bounce. (the solid object would NOT be visible).
OTHERWISE
You could check if outside room(other event) then reverse vertical direction(not sure if it does, but should work)
OTHERWISE
You could do this [code=auto:0]
if y > room_height
{ y = room_height}
if y < 0
{y = 0}
OTHERWISE
you could do the "if a variable has a value" Drag and drop icon. It will give you three blanks. The first being x. In that spot, just put x(this means it takes the x value of the current object), for y put room_height, and for opertation, make sure it says less than. Put this in front of your movement "code"(actions). Now you shouldnt be able to go off the bottom of the screen. HOwever, you can still go off the top. So, what you have to do, is put your movement code in a block. Thats one arrow at the top, and one arrow at the bottom(drag and drop icons). You can figure out which one is start block and which is end by hovering over it with the mouse. So it will read:

If variable has value
-Start block
-movement stuff here
-end block

Thats for your pressed down key. Your gonna do the same idea for the pressed up key except change less than to greater than and room_height to 0. That should work.


Thanks. When I drag the var icon, it has variable, value, and operation. Are you saying put x in the variable?, room_height for value, and smaller then for operation? And that this goes in the down event, just before the move fixed action? It looks like you are saying the first item is "x," not variable.
  • 0

#9 zeldafan1107

zeldafan1107

    Quick Learner

  • New Member
  • 360 posts

Posted 15 April 2008 - 03:58 AM

Very sorry about that. My mistake by x i meant Variable, and Y was supposed to be Value. But you seem to understand that.
  • 0

#10 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 04:02 AM

Very sorry about that. My mistake by x i meant Variable, and Y was supposed to be Value. But you seem to understand that.


Yes, but it is not working for me. In my down event, above my move fixed icon, I have the var icon; I have variable=y, value = room_height, operation = smaller than. I have no var in my up. Just testing down right now. Run the program. I press down and he goes off the screen. Thank you again.
  • 0

#11 zeldafan1107

zeldafan1107

    Quick Learner

  • New Member
  • 360 posts

Posted 15 April 2008 - 04:06 AM

Very odd, for know just put this infront of your movement part then, to see if it works:
i
f y > room_height
{ y = room_height}

thats in execute code btw for the down event
  • 0

#12 RoboBOT

RoboBOT

    GMC Member

  • Validating
  • 592 posts

Posted 15 April 2008 - 04:15 AM

I think I might know the issue. Try putting "room_height + sprite_height" instead of just "room_height". This should help. You see, the way I said before would keep the sprite's origin inside the room, but since the origin is by default at the top left corner of the sprite, the sprite will be able to go just outside the room. (also use "room_width + sprite_width" for the right-key event).

#13 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 04:18 AM

Very odd, for know just put this infront of your movement part then, to see if it works:
i
f y > room_height
{ y = room_height}

thats in execute code btw for the down event


I believe you. But something doesn't make sense. I want to move up, but only until I reach the room_height. So, if I press the up arrow, I hit the up arrow event, test, Am I less than the room_height? Yes, so move up. If not, then don't move. I am saying, if I am less than the top of the room, I can move up.

When this code does work is when I move down and off the screen. Then I cannot move back up and the object is gone.

So I have this in my up event, but the dragon goes off the screen. I don't get it. Room height doesn't make any sense at all for down and there's no room_bottom constant to work with. I used y, 0, and greater than for down. If y is greater than zero then let me press down. But the opposite now takes place. I can move up and if I go off the screen I can never go back down. I'm gone forever.

I'm sure it's simple, but I'm baffled for now.
  • 0

#14 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 04:20 AM

I think I might know the issue. Try putting "room_height + sprite_height" instead of just "room_height". This should help. You see, the way I said before would keep the sprite's origin inside the room, but since the origin is by default at the top left corner of the sprite, the sprite will be able to go just outside the room. (also use "room_width + sprite_width" for the right-key event).


I tried this but it goes off the screen. However, when I go off the bottom of the screen I can never move back up. I'm out of the game. Just can never move back up again.
  • 0

#15 RoboBOT

RoboBOT

    GMC Member

  • Validating
  • 592 posts

Posted 15 April 2008 - 04:21 AM

The room is a bit confusing in how it's arranged: the top-left corner of the room is (0,0). The bottom-right corner of the room is (room_width,room_height). So the higher up on the screen your object is, the smaller it's y value.

#16 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 04:23 AM

The room is a bit confusing in how it's arranged: the top-left corner of the room is (0,0). The bottom-right corner of the room is (room_width,room_height). So the higher up on the screen your object is, the smaller it's y value.


So the lower left if x=0, negative y?
  • 0

#17 johnnyLikesGames

johnnyLikesGames

    GMC Member

  • New Member
  • 18 posts

Posted 15 April 2008 - 04:27 AM

The room is a bit confusing in how it's arranged: the top-left corner of the room is (0,0). The bottom-right corner of the room is (room_width,room_height). So the higher up on the screen your object is, the smaller it's y value.


How can I do a cheap debugger and see what y is based upon my object position? Or can I do that in the debugger? Thank you again.
  • 0

#18 Renegade605

Renegade605

    Xtreme Gamers Ltd.

  • New Member
  • 1333 posts

Posted 15 April 2008 - 04:34 AM

open the game in debug mode (click the red arrow, next to the green one you usually click)
once the game runs, you will have a small debug window, click the plus icon (add a watched expression)
in the prompt, type: "OBJECT_NAME.y" (without quotes; replace OBJECT_NAME with the name of your dragon)
now click somewhere in the room (to focus back in on the game) and try moving around, you should see the value in the box change as you move
  • 0

#19 RoboBOT

RoboBOT

    GMC Member

  • Validating
  • 592 posts

Posted 15 April 2008 - 04:35 AM

You can see your objects x and y position by going to Tools > Show Local Variables > (type in your object's name). This will pop up a box that shows the object's variables, with x and y listed first. You will find that when your object is within the room, the x and y values will never be below 0 or greater than the width or height (respectively).

In the lower left, x=0 and y=room_height

#20 tkirby2003

tkirby2003

    GMC Member

  • New Member
  • 2 posts

Posted 15 April 2008 - 04:55 AM

Try adding the step event -> begin step

Add the check for variable for y < 0

then set move fixed to the middle and a speed of 0

Kirb
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users