AdriandotEXE
Member
Hello GMS 2 users,
I'm pretty new to using Gamemaker Studio 2 and have been following Shaun Spalding's complete platformer tutorials, I'm currently on part 15. Before I posted here, I tried reading through the manual to try to solve the issue and usually I can, however, in this case, I'm not. My problem is that my sprites, which took the place of Shaun's sprites, aren't functioning; meaning the sprites in the tutorial that are labeled as Splayer, SplayerR (R= Run), SplayerA (A=Jump), and Splayerd (d=death). At first, when I replaced the running sprite it worked okay, but when I replaced every Splayer sprite I started to run into real issues. Sometimes I couldn't move my character and other times my character would flicker when I tried walking. I can only deduce that one of three things is causing the issue: (1) I have too many frames possibly because my sprites were animated using 3d models before being turned into 2d pixel sprites. (2) I tried adding a breathing animation to my Splayer sprite which previously had no animation, but removing it did not fix the issue. (3) There could be an issue with the collision box. I've tried playing with the frame rate as well as the collision box shape, but nothing has worked so far. Here is the code for Splayer, that still works for Shaun's sprites:
Create:
hsp = 0;
vsp = 0;
grv = 0.3;
walksp = 4;
controller = 0;
hascontrol = true;
Step:
//Get Player Input
if (hascontrol)
{
key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right)|| keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
if (key_left) || (key_right) || (key_jump)
{
controller = 0;
}
if (abs(gamepad_axis_value (0,gp_axislh)) > 0.2)
{
key_left = abs(min(gamepad_axis_value(0,gp_axislh),0));
key_right = abs(min(gamepad_axis_value(0,gp_axislh),0));
controller = 1;
}
if(gamepad_button_check_pressed(0,gp_face1))
{
key_jump = 1;
controller = 1;
}
}
else
{
key_right = 0;
key_left = 0;
key_jump = 0;
}
// Calculate Movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x, y+1,Owall)) and (key_jump)
{
vsp= -7;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,Owall))
{
while (!place_meeting(x+sign(hsp),y, Owall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,Owall))
{
while (!place_meeting(x,y+sign(vsp),Owall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
// Animation
if(!place_meeting(x,y+1,Owall))
{
sprite_index = SplayerA;
image_speed = 0;
if(sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
if(sprite_index == SplayerA)
{
audio_sound_pitch(snLanding,choose(0.8,1.0,1.1));
audio_play_sound(snLanding,4,false);
}
image_speed = 1;
if (hsp==0)
{
sprite_index = Splayer
}
else
{
sprite_index = SplayerR;
}
}
if(hsp != 0) image_xscale = sign(hsp)
Room Start:
///@desc Auto-Save
// overwrite old save
if (file_exists(SAVEFILE)) file_delete(SAVEFILE);
///Create a new save
var file;
file = file_text_open_write(SAVEFILE);
file_text_write_real(file,room);
file_text_close(file);
Animation End:
if (sprite_index == SplayerR) audio_play_sound(choose(snStep1,snStep2,snStep3,snStep4),1,false);
Oenemy:
/// desc Die
with(Ogun) instance_destroy();
instance_change(Opdead,true);
direction = point_direction(other.x,other.y,x,y);
hsp =lengthdir_x(6,direction);
vsp =lengthdir_y(4,direction)-2;
if(sign(hsp) != 0) image_xscale = sign(hsp);
I'm pretty new to using Gamemaker Studio 2 and have been following Shaun Spalding's complete platformer tutorials, I'm currently on part 15. Before I posted here, I tried reading through the manual to try to solve the issue and usually I can, however, in this case, I'm not. My problem is that my sprites, which took the place of Shaun's sprites, aren't functioning; meaning the sprites in the tutorial that are labeled as Splayer, SplayerR (R= Run), SplayerA (A=Jump), and Splayerd (d=death). At first, when I replaced the running sprite it worked okay, but when I replaced every Splayer sprite I started to run into real issues. Sometimes I couldn't move my character and other times my character would flicker when I tried walking. I can only deduce that one of three things is causing the issue: (1) I have too many frames possibly because my sprites were animated using 3d models before being turned into 2d pixel sprites. (2) I tried adding a breathing animation to my Splayer sprite which previously had no animation, but removing it did not fix the issue. (3) There could be an issue with the collision box. I've tried playing with the frame rate as well as the collision box shape, but nothing has worked so far. Here is the code for Splayer, that still works for Shaun's sprites:
Create:
hsp = 0;
vsp = 0;
grv = 0.3;
walksp = 4;
controller = 0;
hascontrol = true;
Step:
//Get Player Input
if (hascontrol)
{
key_left = keyboard_check(vk_left) || keyboard_check(ord("A"));
key_right = keyboard_check(vk_right)|| keyboard_check(ord("D"));
key_jump = keyboard_check_pressed(vk_space);
if (key_left) || (key_right) || (key_jump)
{
controller = 0;
}
if (abs(gamepad_axis_value (0,gp_axislh)) > 0.2)
{
key_left = abs(min(gamepad_axis_value(0,gp_axislh),0));
key_right = abs(min(gamepad_axis_value(0,gp_axislh),0));
controller = 1;
}
if(gamepad_button_check_pressed(0,gp_face1))
{
key_jump = 1;
controller = 1;
}
}
else
{
key_right = 0;
key_left = 0;
key_jump = 0;
}
// Calculate Movement
var move = key_right - key_left;
hsp = move * walksp;
vsp = vsp + grv;
if (place_meeting(x, y+1,Owall)) and (key_jump)
{
vsp= -7;
}
//Horizontal Collision
if (place_meeting(x+hsp,y,Owall))
{
while (!place_meeting(x+sign(hsp),y, Owall))
{
x = x + sign(hsp);
}
hsp = 0;
}
x = x + hsp;
//Vertical Collision
if (place_meeting(x,y+vsp,Owall))
{
while (!place_meeting(x,y+sign(vsp),Owall))
{
y = y + sign(vsp);
}
vsp = 0;
}
y = y + vsp;
// Animation
if(!place_meeting(x,y+1,Owall))
{
sprite_index = SplayerA;
image_speed = 0;
if(sign(vsp) > 0) image_index = 1; else image_index = 0;
}
else
{
if(sprite_index == SplayerA)
{
audio_sound_pitch(snLanding,choose(0.8,1.0,1.1));
audio_play_sound(snLanding,4,false);
}
image_speed = 1;
if (hsp==0)
{
sprite_index = Splayer
}
else
{
sprite_index = SplayerR;
}
}
if(hsp != 0) image_xscale = sign(hsp)
Room Start:
///@desc Auto-Save
// overwrite old save
if (file_exists(SAVEFILE)) file_delete(SAVEFILE);
///Create a new save
var file;
file = file_text_open_write(SAVEFILE);
file_text_write_real(file,room);
file_text_close(file);
Animation End:
if (sprite_index == SplayerR) audio_play_sound(choose(snStep1,snStep2,snStep3,snStep4),1,false);
Oenemy:
/// desc Die
with(Ogun) instance_destroy();
instance_change(Opdead,true);
direction = point_direction(other.x,other.y,x,y);
hsp =lengthdir_x(6,direction);
vsp =lengthdir_y(4,direction)-2;
if(sign(hsp) != 0) image_xscale = sign(hsp);