Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075922 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 03:48:30 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)GM N00B Question
Pages: [1]
Print
Author Topic: GM N00B Question  (Read 1292 times)
Calum Bowen
Level 4
****



View Profile WWW Email
« on: July 17, 2012, 07:06:31 PM »

I want to make my object move (x += 3) once when i press the right key down and only move that direction again once the key has been released and then pressed again. At the moment it moves a few times as it reads me pressing down the right key.

I have 4 different objects - one is character standing still facing right (oStillR), one is character step right (oMoveR), one is character standing still facing left (oStillL), the last is character step left (oMoveR). The character is a slug.

I want to press a direction from the standing still position and have it change to the respective step object and then back again from that object when you press the same direction again.

I hope this makes sense and i'm sure people will be able to easily see my errors! At the moment very little of what i wish to work is working...

Here's the code for my objects:

oMoveL - step event:

Code:
if (keyboard_check(vk_right))
                       {
                       x += 3;
                       instance_destroy()
                       instance_create(x, y, oStillR)
                       }
                       if (keyboard_check(vk_left))
                       {
                       x -= 3;
                       instance_destroy()
                       instance_create(x, y, oStillL)
                       }           

oStillL - step event:
                               
Code:
if(keyboard_check(vk_right))
                                 {
                                 x += 3;
                                 instance_destroy()
                                 instance_create(x,y, oStillR)
                                 }
                                 if (keyboard_check(vk_left))
                                 {
                                 x -= 3;
                                 instance_destroy()
                                 instance_create(x,y, oMoveL)
                                 }

oStillR - step event:
                   
Code:
  if (keyboard_check(vk_right))
                     {
                     x += 3;
                     instance_destroy()
                     instance_create(x, y, oMoveR)
                     }
                     if (keyboard_check(vk_left))
                     {
                     x -= 3;
                     instance_destroy()
                     instance_create(x, y, oStillL)
                     }

oMoveR - step event:
               
Code:
if (keyboard_check(vk_right))
                {
                x += 3;
                instance_destroy()
                instance_create(x, y, oStillR)
                }
                if (keyboard_check(vk_left))
                {
                x -= 3;
                instance_destroy()
                instance_create(x, y, oStillL)
                }

Thanks!
Logged

ink.inc
Guest
« Reply #1 on: July 17, 2012, 07:10:58 PM »

why is your player character 4 separate objects
Logged
Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #2 on: July 17, 2012, 07:16:41 PM »

hmm... the movement is really blocky - the walk animation is 2 frames - it's a slug - one is straight down and the other is with a bend in the middle - so i wanted that to almost animate as you move it... which is why i thought if i made each frame (all two of them) a different object i could say - when you press right it goes to the bent sprite when you press right again it goes to the straight sprite etc.

And then there's four because I duplicated it for turning left etc.

I suppose I'm doing this the wrong way?

EDIT: HERE'S MY SLUG. OK, i can't work out how to post an img - here's links: http://imageshack.us/photo/my-images/26/slug1.png/ and http://imageshack.us/photo/my-images/837/slug2.png/
« Last Edit: July 17, 2012, 07:22:43 PM by Calum Bowen » Logged

ink.inc
Guest
« Reply #3 on: July 17, 2012, 07:27:38 PM »

yeah, that's a really hackish way of doing it

i haven't touched gm in ages, but here's how i would do it (assuming i'm reading your desired results correctly):

1 player object (oSlug)

CREATE:
image_speed=0;

STEP:
if keyboard_check_pressed(vk_right)
{
x+=3;
image_index+=1;
}
if keyboard_check_pressed(vk_left)
{
x-=3;
image_index+=1;
}
Logged
Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #4 on: July 17, 2012, 07:32:07 PM »

Amazing! Thank you for the quick response - solved it right away!
Logged

mokesmoe
Level 10
*****



View Profile WWW Email
« Reply #5 on: July 17, 2012, 09:47:41 PM »

Also "image_xscale = -1" will flip the sprite for you. I think it's pro only though. (If you have lite.)
Logged
Zack Bell
Level 10
*****



View Profile WWW
« Reply #6 on: July 17, 2012, 10:19:00 PM »

If you plan to use image_xscale to flip the sprite, make sure that the sprite's x origin is at its center.

Just a heads up.
Logged

Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #7 on: July 17, 2012, 10:22:31 PM »

Thank you mokesmoe & Zack Bell - that helps - I was on the verge of using two objects. I certainly have much to learn.
Although I'm on lite right now, I was waiting for a stumbling point with it so now might as well be as good a time as ever to go pro.
Logged

---
Level 10
*****


View Profile
« Reply #8 on: July 17, 2012, 10:50:16 PM »

If you're using 8.1, I believe they allow image_xscale/image_yscale/image_angle/image_blend in the lite edition.
Logged
mokesmoe
Level 10
*****



View Profile WWW Email
« Reply #9 on: July 18, 2012, 01:20:11 AM »

For a non-image_xscale approach: instead of two objects, use two sprites. In the vk_right section set sprite_index to sSlugRight (Guessing at your naming scheme) and then to sSlugLeft in the vk_left part.
Logged
ink.inc
Guest
« Reply #10 on: July 18, 2012, 11:57:15 AM »

PS: To post an image, just put it within img tags, like so:

Code:
[img]image url[/img]
Logged
Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #11 on: July 18, 2012, 12:14:53 PM »

Mokesmoe - that helps a lot! thank you.

John - does that mean i have to upload every image i want to post somewhere to the internet in order to get an image url?

(game maker n00b questions turned into general n00b questions)

I have hit another GM stumbling block...

So I want a raindrop to fall from a cloud onto the floor. I have a rain splash animation sprite and a static rain drop. The plan was to have one drop of rain fall at random (between 1-3 seconds) intervals and to splash once it hits the floor (tile).

so oRainDrop - create event - i used the move fixed tool. The issue I have is that it produces multiple rain drops all moving at nearly the same time. This is probably something simple. I've tried using alarms and the "firingdelay" principle in the Game Maker Tuts II (with the space ship shooting stuff). But I'm ending up with a constant pouring of too many rain drops!

I think it'd be best for me to solve this issue before moving onto the floor splash. (Is it possible to code a collision between a specific tile and an object? I tried making invisible objects where the rain hits the floor but these didn't seem to do anything.... anyway, i won't go too far into my thoughts on how to attempt doing that right now.

I think it's probably a common mistake but I cannot seem to work out how to only get one instance of my object moving not an infinite chain of them.

Thanks again you guys - you've proved really helpful thus far and i feel a little cheeky posting all of my struggles but it's been a good few hours of watching TOO MUCH RAIN! :  )

« Last Edit: July 18, 2012, 12:29:15 PM by Calum Bowen » Logged

Zack Bell
Level 10
*****



View Profile WWW
« Reply #12 on: July 18, 2012, 12:30:17 PM »

I think you want something like this:

Code:
//create event of cloud

can_drip = true;

Code:
//step event of cloud

if (can_drip) {
    alarm[0] = random_range(40, 80);
    can_drip = false;
}

Code:
//alarm[0] of cloud

instance_create(x, y, oRainDrop);
can_drip = true;


Code:
//rain drop's collision event with floor

sprite_index = sSplashAnimation;


Code:
//rain drop's animation end event

instance_destroy();

Hope I understood your issue.
Logged

ink.inc
Guest
« Reply #13 on: July 18, 2012, 12:36:51 PM »

does that mean i have to upload every image i want to post somewhere to the internet in order to get an image url?

uh, yeah

problems

i don't know how you're doing it currently but what you're gonna want to do is set up a cloud object that creates instances of oRaindrop at given intervals.

oCloud
Code:
CREATE:
timer=0;
timer_max=5;
amount=3;

STEP:
if (timer<timer_max)
{
timer+=1;
}
else
{
repeat(amount)instance_create(x+choose(random(10),-random(10)),y,oRaindrop);
timer=0;
}

oRaindrop
Code:
CREATE:
sprite_index=sRainDrop;

STEP:
if (place_meeting(x,y,oFloor))//if it collides with a floor object
{
sprite_index=sRainSplash;
}
else
{
y+=5;
}
ANIMATION END://this event can be found in ADD EVENT/OTHER/ANIMATION END
if (sprite_index==sRainSplash)
instance_destroy();

Logged
Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #14 on: July 18, 2012, 12:47:46 PM »

Thank you both - i give the code a try! You guys are really helping me progress with my first game! This should keep me going for a while  Wink
Logged

Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #15 on: August 02, 2012, 12:12:15 PM »

OK! Next problem:

When the slug gets hit with rain it goes red (separate sprite - sSlugScream) so i'm

Code:
if(place_meeting(x,y,oDrop))

{
sprite_index=sSlugScream;
}

if (sprite_index=sSlugScream)
{
if (timer<timer_max)
{
timer+=1;
}
else
{
sprite_index=sSlugR
}           

For some reason, it only goes red once. The following times it gets hit it doesn't change to sSlugScream anymore just stays normal.
Does anyone know why it's doing this?
Logged

Sean A.
Level 8
***



View Profile Email
« Reply #16 on: August 02, 2012, 12:43:09 PM »

You are missing a closing curly brace, that could be part of it. Also code is easier to read when tabbed
Logged
Glyph
Level 9
****


Relax! It's all a dream! It HAS to be!


View Profile
« Reply #17 on: August 02, 2012, 12:57:34 PM »

It needs to reset that timer each time, I'd assume - after saying 'sprite_index=sSlugScream;', add a line with 'timer=0' or whatever. Also, yeah, the closing bracket.
Logged

    
Try out my games!
Calum Bowen
Level 4
****



View Profile WWW Email
« Reply #18 on: August 04, 2012, 01:49:36 PM »

Thanks guys - that fixed it!

The bracket thing was my failure to copy the whole of the code - it's in there.

onwards and upwards until the next problem arises. : )
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic