GameMaker draw_sprite(animation does not work)

K

KonseRva_23

Guest
The function draw_sprite(sprite_index,subimage,x,y) with the value "-1" in the "subimage" should draw an animation from all the sprite frames "sprite_index", but it does not. But in another project everything works as it should.
 

Attachments

K

KonseRva_23

Guest
sprite?

What did you mean?
 
Last edited by a moderator:

Amon

Member
Did you drag it from the resources section into the room? When you do that does the anim play?
 
K

KonseRva_23

Guest
Yes.
I did the same with the same sprite, but in another project and everything works there

Screenshots. If this helps.
 

Attachments

Last edited by a moderator:

Amon

Member
In the first pic, try changing the 'frames per second' to 'frames per game frame'.

Something else must be wrong with your project because what I have suggested and what you are showing, it should work.
 
Last edited by a moderator:
K

KonseRva_23

Guest
[QUOTE = "Amon, post: 298370, участник: 5511"] На первом рисунке попробуйте изменить «кадры в секунду» на «кадры на игровой фрейм». [/ QUOTE]
Все еще не работает
Но, может быть, я дам вам свой проект, и вы поймете, что случилось.
 

TsukaYuriko

☄️
Forum Staff
Moderator
Normally, I'd be sending out PMs for all this... but the sheer amount I'd have to send makes it more practical to include it in a reply. :p

Some things to keep in mind when posting here...

Please do not post screenshots of code. Code is text, meant to be posted as text. For further information: How to Q&A

The GMC is an English community. Posts exclusively in other languages are not allowed.

Please keep messages contained within one sequential reply. This is not a chat, this is a forum. Multiple messages in a row by the same member are only allowed under specific circumstances. For further information: Community Guidelines


That aside... what is the exact problem? Does the sprite not draw at all? Does it draw but not animate?
I see a Create event and a Step event, but not their code. Please post all relevant code.
 
K

KonseRva_23

Guest
Event step :
#region Motion
// gravity
if (!place_meeting(x,y+1,o_wall))
{
if(vsp < 15)
vsp += 0.7

}
else
{
vsp = 0;
}

if(!place_meeting(x,y+1,o_wall))
{
switch(turn)
{
case "l":
sprite = s_Henry_l_jump;
break;

case "r":
sprite = s_Henry_r_jump;
break;
}

}

if(place_meeting(x,y,o_wall))
{
while(place_meeting(x,y,o_wall))
{
y-=1;
}
}

// moving
// left

if (keyboard_check(vk_left))
{
turn = "l";
if(place_meeting(x,y+1,o_wall))
sprite = s_Henry_l_walk;
if(place_empty(x-6,y))
hsp = -6;
}


// right


if (keyboard_check(vk_right))
{
turn = "r";
if(place_meeting(x,y+1,o_wall))
sprite = s_Henry_r_walk;
if(place_empty(x+6,y))
hsp = 6;
}


// jump


if (keyboard_check_pressed(vk_up))
{
vsp = -12;
}


if(place_meeting(x,y+1,o_wall))
{
if(!keyboard_check(vk_right) & !keyboard_check(vk_left))
{
switch(turn)
{
case "l":
sprite = s_Henry_l_wait;
break;

case "r":
sprite = s_Henry_r_wait;
break;
}
}
}



x += hsp;
y += vsp;
hsp = 0;
#endregion


Event create :

hp = 100;
def = 0;
atk = 0;

vsp = 0;
hsp = 0;

sprite = s_Henry_l_wait;
turn = "l";
 

TsukaYuriko

☄️
Forum Staff
Moderator
Ensure that the instance's image_speed is set to a value that allows the animation to play at a perceivable speed (and, therefore, that image_index is updating properly). Also, please answer the remaining open question of my previous post.
 
Last edited:
N

NeZvers

Guest
Why do you have -1 in sub image?
if I'm right that means - show nothing. Put in image_index instead.
If you haven't disabled default sprite then whatever sprite you'll draw it wont display more sub_images than default sprite.
Code:
//Create event
sprite = sprite_index; // to set first sprite the same as default
sprite_index = -1; // disable default sprite so draw_sprite work properly
image_speed = 0.25; // Adjust to your needs since now 1 means sub image changes each frame

//draw event
draw_sprite(sprite,image_index,x,y);
 
T

TimothyAllen

Guest
I THINK that if the calling instance does not of a sprite assigned to it, the image_index will remain at zero. I'm not sure because I haven't bothered to test it. But you might try assigning your instance a sprite, or create your own indexing variable.
 
K

KonseRva_23

Guest
The same function "draw_sprite" with -1 in "subimage" works in GMS 2 as it should (that is it shows all the frames of the sprite), but in another project. But in the current project it does not work, although in another project I drew that The same sprite with the same properties.

That aside... what is the exact problem? Does the sprite not draw at all? Does it draw but not animate?
The problem is that only the first frame of the sprite is drawn, although it should draw the animation from all frames, since in the "subimage" the value is -1.
 

TheouAegis

Member
@KonseRva_23 Does the object with this code in it have a sprite_index already assigned to it and does that sprite_index have enough frames? Or does the object have no sprite_index assigned to it?
 
K

KonseRva_23

Guest
The object has a variable "sprite" in which is "sprite_index", which has more than one frame.
 
T

TimothyAllen

Guest
The object has a variable "sprite" in which is "sprite_index", which has more than one frame.
You're totally not getting it.

Is the object assigned a sprite? We realize that you are attempting to use your own variable to draw a specific sprite. BUT if the object is not assigned a sprite... then its image_index will never increment. I'm almost positive that this is your issue.

So, to fix this problem, do not use -1 as the image_index parameter. Instead, use your own index variable which you increment by the image_speed each frame.
OR
If you are literally doing: draw_sprite(sprite, -1, x, y) then why even use a custom variable. Simply set sprite_index instead of using sprite.
 
Last edited by a moderator:

CMAllen

Member
A few things -- First, if you assign an object a sprite that only has 1 frame, then the only value it can ever return for image_index is 0 because the value and range of image_index are based on the number of sub-images in the currently assigned sprite. Two, if the animation playback rate is 0 or if the image_speed is 0, then image_index will never increment. Third, if an object that has no sprite is told to draw a sprite, its image_index value will only ever return 0, because the non-sprite it is using has no sub-image values.
 
K

KonseRva_23

Guest
The problem is solved. I put the sprite with the animation in the sprite object in its properties, and now all the animations are working.
 
Top