Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411526 Posts in 69381 Topics- by 58436 Members - Latest Member: GlitchyPSI

May 02, 2024, 05:46:15 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Game Maker Inheritance question
Pages: [1]
Print
Author Topic: Game Maker Inheritance question  (Read 2568 times)
Massena
Level 4
****


Satisfied.


View Profile
« on: December 13, 2009, 10:24:13 AM »

I am very new to Game Maker and while starting a project this is how I setup things:
I had a "character" object that had no sprite and on Creat defined some variables like:

Code:
walking_speed = 2;
walking_right = false;
walking_left = false;
facing = "left";
//and some more

on the Step event I had:

Code:
if (walking_right) {
    x += walk_speed;
    facing = "right";
}

if (walking_left) {
    x -= walk_speed;
    facing = "left";
}

then I created an object "warrior" whose parent was "character" that had a sprite, and finally an object "player" whose parent was "warrior" and that had

Code:
if (keyboard_check(vk_right))
    walking_right = true;
else
    walking_right = false;

if (keyboard_check(vk_left))
    walking_left = true;
else
    walking_left = false;

and the "Call Event" action, in its Step event.

When I place the player object in a Room, I don't see the warrior sprite and nothing happens. I'm probably doing something fundamentally wrong and warrior's Draw event isn't being called. Can anyone explain to me where I'm messing up?

Sorry for the long post!
Logged

Codestar
Level 1
*

One man, one game


View Profile WWW
« Reply #1 on: December 13, 2009, 10:33:05 AM »

you have to set the sprite_index of the object in your step event. you also have to have it draw the sprite in the draw event

something like
draw_sprite(sprite_index,-1,x,y);
Logged



Check out my current game project:
Mine to the sky
Massena
Level 4
****


Satisfied.


View Profile
« Reply #2 on: December 13, 2009, 10:36:29 AM »

Where do I do that? In "warrior" or "player"?

Thanks for the fast reply!

edit: Got it working!

"warrior" now has in its Step event, besides the Call Event action:

Code:
if (walking_right)
    sprite_index = warrior_walk_right;

if (walking_left)
    sprite_index = warrior_walk_left;
   
if (!walking_left && !walking_right) {
    if (facing = "left")
        sprite_index = warrior_stand_left;
    if (facing = "right")
        sprite_index = warrior_stand_right;
}

in Create:

Code:
sprite_index = warrior_stand_right;
(and Call Event, as always)

and in Draw:

Code:
draw_sprite(sprite_index, image_index, x, y);

Hope that helps someone!

« Last Edit: December 13, 2009, 11:09:44 AM by Massena » Logged

JMickle
Level 10
*****



View Profile
« Reply #3 on: December 13, 2009, 12:10:42 PM »

the problem was that sprites aren't inherited. this was inadvertently fixed because the sprite_index value change WAS inherited. you did everything right though, the only change you should do is to remove the sprite from the warrior object, to save a bit of memory i guess.

not necessary though.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic