Jump to content


Photo

Changing sprite upon collision


  • Please log in to reply
7 replies to this topic

#1 Mani-Mani

Mani-Mani

    GMC Member

  • New Member
  • 74 posts

Posted 12 December 2010 - 03:55 AM

I want to change from spr_Playerfall to spr_Playerwalk (or spr_Playerstand, depending on whether or not they are walking) upon collision with obj_floor.

Can someone recommend how I might go about doing this?


  • 0

#2 slayer 64

slayer 64

    GMC Member

  • GMC Member
  • 3726 posts
  • Version:GM8.1

Posted 12 December 2010 - 04:19 AM

use sprite_index
  • 0

#3 Mani-Mani

Mani-Mani

    GMC Member

  • New Member
  • 74 posts

Posted 12 December 2010 - 04:22 AM

use sprite_index


So, like, collision with obj_floor, then code put that in? How does that work?
  • 0

#4 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2917 posts
  • Version:GM:Studio

Posted 12 December 2010 - 10:52 AM

So, like, collision with obj_floor, then code put that in? How does that work?

In the collision with floor event:
sprite_index = Playerstand;
Or using D&D
Collision Event
:GM108:
Subimage 0
speed 0
  • 0

#5 Mani-Mani

Mani-Mani

    GMC Member

  • New Member
  • 74 posts

Posted 12 December 2010 - 01:53 PM


So, like, collision with obj_floor, then code put that in? How does that work?

In the collision with floor event:
sprite_index = Playerstand;
Or using D&D
Collision Event
:GM108:
Subimage 0
speed 0


Okay, I'll do that... wait, that's what I've been doing. I've got some variables governing direction, and I'm trying to use them to make your sprite direction to change, as well, the stand has subimages I want it to scroll through, and I can't seem to get it to work.


  • 0

#6 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2917 posts
  • Version:GM:Studio

Posted 12 December 2010 - 02:05 PM

Change the sub image speed to something like 0.3 or use:
image_speed = 0.3;
This will then scroll through the sub-images.
  • 0

#7 Mani-Mani

Mani-Mani

    GMC Member

  • New Member
  • 74 posts

Posted 12 December 2010 - 02:12 PM

Change the sub image speed to something like 0.3 or use:
image_speed = 0.3;
This will then scroll through the sub-images.

Okay, well, here's what I've got for the object-

Collision Event with object obj_floor:
move in direction direction at most -1 till a contact with solid objects
set the vertical speed to 0
if vspeed is not equal to 0
      if hspeed is equal to 0
         if global.direc is equal to 0
         set the sprite to Dew-SL with subimage 0 and speed 1
         if global.direc is equal to 1
         set the sprite to Dew-SR with subimage 0 and speed 1
      if hspeed is not equal to 0
        if global.direc is equal to 0
        set the sprite to Dew-WL with subimage 0 and speed 1
        if global.direc is equal to 1
        set the sprite to Dew-WR with subimage 0 and speed 1
And it retains the falling image after the collision.



  • 0

#8 Noele

Noele

    GMC Mentor

  • GMC Member
  • 2917 posts
  • Version:GM:Studio

Posted 12 December 2010 - 05:26 PM

move in direction direction at most -1 till a contact with solid objects
set the vertical speed to 0
if vspeed is not equal to 0

Testing the vspeed to see if it is not equal to zero after setting it to zero (set the vertical speed to zero) would prevent execution.
Maybe something like this may work for you?

move_contact_solid(direction,-1);
vspeed = 0; // stop vertical movement
if(hspeed == 0) // there is no horizontal movement
{
  if(global.direct == 0)
  {
    sprite_index = Dew_SL;
  }else{
    sprite_index = Dew_SR;
  }
}else{ // there must be some horizontal movement
  if(global.direct == 0)
  {
    sprite_index = Dew_WL;
  }else{
    sprite_index = Dew_WR;
  }
}
image_index = 0;
image_speed = 1; // reduce to 0.5 for slower speeds  

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users