Need help with GML!
#1
Posted 22 February 2012 - 06:36 PM
What i want is :-
When i right click my character, I want it to play the attack animation and at the end of the animation i want it to create a fireball.
Object8 = Fireball
Mage = The character.
if global.facing="R"
{
sprite_index = MAright
image_index += 1
if image_index = 10
{
instance_create(Mage.x,Mage.y,object8)
motion_set(180,6)
}
sprite_index = Mright
}
It spawns the fireball but doesnt play the animation properly. Help please.
#2
Posted 22 February 2012 - 06:41 PM
I have never used motion_set so I'm not sure about that, but is this happening inside the mage step event? If it is, wouldn't motion_set set the motion of the mage and not the fireball?I have been having problems trying to figure out how to shoot in a particular direction at the proper sub image.
What i want is :-
When i right click my character, I want it to play the attack animation and at the end of the animation i want it to create a fireball.
Object8 = Fireball
Mage = The character.
if global.facing="R"
{
sprite_index = MAright
image_index += 1
if image_index = 10
{
instance_create(Mage.x,Mage.y,object8)
motion_set(180,6)
}
sprite_index = Mright
}
It spawns the fireball but doesnt play the animation properly. Help please.
#3
Posted 22 February 2012 - 07:09 PM
var i;
i = instance_create(Mage.x,Mage.y,object8);
with i {
motion_set(180,6);
}
EDIT:
Alternately, you could do this (which should be faster because motion_set takes into account current motion as well - of which there is none)
var i; i = instance_create(Mage.x,Mage.y,object8); i.speed = 6; i.direction = 180;
Edited by AKSuperNewb, 22 February 2012 - 07:10 PM.
#4
Posted 22 February 2012 - 07:09 PM
I have never used motion_set so I'm not sure about that, but is this happening inside the mage step event? If it is, wouldn't motion_set set the motion of the mage and not the fireball?
[/quote]
True that! the fireballs motion is fixed but the animation is still not playing :S
#5
Posted 22 February 2012 - 07:12 PM
In the event you'd put something that would first check if the sprite was the MAright sprite, then it would create a fireball and then it would change you back to the Mright sprite.
#6
Posted 22 February 2012 - 07:16 PM
var i;
i = instance_create(Mage.x,Mage.y,object8);
with i {
motion_set(180,6)
}
The animation still doesnt play
#7
Posted 22 February 2012 - 07:19 PM
EDIT: It's also possible you meant to simply put the sprite_index = Mright code in the "if" block. I'm pretty sure that would make it work as well, since that seems to be our intention. i.e.,
if global.facing="R"
{
sprite_index = MAright
image_index += 1
if image_index = 10
{
instance_create(Mage.x,Mage.y,object8)
motion_set(180,6)
sprite_index = Mright
}
}
Edited by AKSuperNewb, 22 February 2012 - 07:21 PM.
#8
Posted 22 February 2012 - 07:33 PM
Except it doesnt shoot the fireball when its standing still :/
Heres my code now :
if mouse_check_button(mb_right)
if sprite_index = Mright
{
hspeed = 0
sprite_index = MAright
image_index += 0.5
if image_index = 10
{
instance_create(Mage.x,Mage.y,object8)
motion_set(360,6)
sprite_index = Mright
}
}
Edited by _255240, 22 February 2012 - 07:36 PM.
#9
Posted 22 February 2012 - 07:42 PM
^Thanks alot! that worked like a charm! ty all!
Except it doesnt shoot the fireball when its standing still :/
Heres my code now :
if mouse_check_button(mb_right)
if sprite_index = Mright
{
hspeed = 0
sprite_index = MAright
image_index += 0.5
if image_index = 10
{
instance_create(Mage.x,Mage.y,object8)
motion_set(360,6)
sprite_index = Mright
}
}
What sprite is the mage when he's standing still? Because if the sprite isn't Mright while you're standing still (i.e. the sprite might be "Midle" or something) then the code would check:
Right mouse pressed? -Check
Sprite = Mright? -Nope! I shan't continue!
Oh, btw, motion_set(360, 6) is the same as motion_set(0, 6) and using 0 is sexier!
Edited by DivideBy2, 22 February 2012 - 07:43 PM.
#10
Posted 22 February 2012 - 07:43 PM
^Thanks alot! that worked like a charm! ty all!
Except it doesnt shoot the fireball when its standing still :/
Heres my code now :
if mouse_check_button(mb_right)
if sprite_index = Mright
{
hspeed = 0
sprite_index = MAright
image_index += 0.5
if image_index = 10
{
instance_create(Mage.x,Mage.y,object8)
motion_set(360,6)
sprite_index = Mright
}
}
What sprite is the mage when he's standing still? Because if the sprite isn't Mright while you're standing still (i.e. the sprite might be "Midle" or something) then the code would check:
Right mouse pressed? -Check
Sprite = Mright? -Nope! I shan't continue!
The image of the sprite standing still is the sub image of him walking.
Edited by _255240, 22 February 2012 - 07:43 PM.
#11
Posted 23 February 2012 - 10:40 AM
#12
Posted 23 February 2012 - 01:17 PM
if mouse_check_button(mb_right) && sprite_index = Mright && !isattacking
isattacking = 1;
if isattacking {
hspeed = 0;
sprite_index = MAright;
image_index += 0.5;
if image_index >= 10 {
instance_create(Mage.x, Mage.y, object8);
motion_set(360, 6);
sprite_index = Mright;
isattacking = 0;
}
}
Not sure if it'll fix your problem, but it's better this way anyway.Also here's just a quick extra tidbit of information:
It's good practise to start all your sprite names with spr_ and object names with obj_
So you can do spr_mage and obj_mage, and you'd know what type of item it is.
Also, you might want to rename your fireball object to something more obvious like obj_fireball
It's not required, but it's just something I recommend doing.
Edited by DivideBy2, 23 February 2012 - 01:20 PM.
#13
Posted 24 February 2012 - 01:42 PM
MOVEMENT CODE :
hspeed = (keyboard_check(vk_right)-keyboard_check(
vk_left))*3;
if keyboard_check_pressed(vk_right)
{
sprite_index = Mright
}
if hspeed = 0 and isattacking = 0
{ image_index=0 }
hspeed = (keyboard_check(vk_right)-keyboard_check(
vk_left))*3;
if keyboard_check_pressed(vk_left)
{
sprite_index = Mleft
}
if hspeed = 0 and isattacking = 0
{ image_index=0 }PROJECTILES
if mouse_check_button(mb_right)and sprite_index = Mright and !isattacking
isattacking = 1;
if isattacking {
hspeed = 0;
sprite_index = MAright;
image_index += 0.5;
if image_index >= 10 {
instance_create(Mage.x, Mage.y, fireball);
isattacking = 0;
}sprite_index = Mright;
}
if mouse_check_button(mb_right) and sprite_index = Mleft and !isattacking
isattacking = 1;
if isattacking {
hspeed = 0;
sprite_index = MAleft;
image_index += 0.5;
if image_index >= 10 {
i=instance_create(Mage.x, Mage.y, fireball)
isattacking = 0;
}sprite_index = Mleft;
}
Edited by _255240, 24 February 2012 - 02:02 PM.
#14
Posted 24 February 2012 - 05:47 PM
First of all your movement code can be greatly cut down.
hspeed = (keyboard_check(vk_right)-keyboard_check(
vk_left))*3;
if (hspeed>0){sprite_index = Mright;}
if (hspeed<0){sprite_index = Mleft;}
if hspeed = 0 and isattacking = 0
{ image_index=0 }
Secondly the problem in your firing code is the "isattacking" variable
if mouse_check_button(mb_right)and sprite_index = Mright and !isattacking
isattacking = 1;
if isattacking{
if (sprite_index == Mright || sprite_index == MAright){
hspeed = 0;
sprite_index = MAright;
image_index += 0.5;
if image_index >= 10 {
instance_create(Mage.x, Mage.y, fireball);
isattacking = 0;
sprite_index = Mright; //This code was after the end bracket of the if statement...thus was ending the attack sequence before was fully shown
}
}
}
if mouse_check_button(mb_right) and sprite_index = Mleft and !isattacking
isattacking = 1;
if isattacking {
if (sprite_index == Mleft || sprite_index == MAleft){
hspeed = 0;
sprite_index = MAleft;
image_index += 0.5;
if image_index >= 10 {
i=instance_create(Mage.x, Mage.y, fireball)
isattacking = 0;
sprite_index = Mleft;
}
}
}
That should fix the issue.
#15
Posted 24 February 2012 - 05:59 PM
But while your here can you help me with another issue?
I'd like my character to move where its clicked, only on the X-axis. I only want it to move left and right and change attack and moving sprites appropriately.
Coding is not necessary as I'd like to learn. If coding just put some comments here and there so my brain doesnt break.. Thankyou!
Edit :
Marker is the object to which my character should go to on the x axis. When it gets near to the marker, the marker should be destroyed and the speed set to 0. this is what i came up with:
if instance_exists(marker)
{
move_towards_point(marker.x,y,3);
}
if point_distance(x,y,marker.x,y)<10
with (marker)
{
instance_destroy()
};
I want it the object marker to be destroyed when the x axis of the Player and the marker are same. So far havent been very successful! Need help!
Edited by _255240, 26 February 2012 - 07:23 PM.
#16
Posted 26 February 2012 - 07:25 PM
#17
Posted 27 February 2012 - 01:51 AM
So when the mouse clicks, set a variable called targetX to the mouse_x variable.
Then in the step event:
if (point_distance(x,y,targetX,y) > hspeed){
move_towards_point(targetX,y,3);
}
If you have a question about how the code works, let me know =)
EDIT: actually you wouldn't need the point_distance function
if (abs(x-targetX) > hspeed){
move_towards_point(targetX,y,3);
}
That's probably going to be more efficient code although it doesn't really matter. lol
Edited by 111Studio, 27 February 2012 - 01:58 AM.
#18
Posted 27 February 2012 - 10:55 AM
if distance_to_object(marker)<1
with (marker)
{
instance_destroy()
};got it to work
Edited by _255240, 27 February 2012 - 11:15 AM.
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users











