Log in
Search
GameML File Sharing
USERNAME: gamemladmin@gmail.com PASSWORD: gamemlsite Upload Here: https://gameml.forumotion.com/GameML-File-Sharing-h3.htmPlease add only games.Point to mouse with lite.
5 posters
:: Game Making :: Game Maker Help :: Game Dev. Q&A :: GML help (Coding)
Page 1 of 1
Point to mouse with lite.
With GM pro one of the features is being able to make a sprite point towards the mouse, and us guys that only have lite can't stand that we can't use it. But with a different line of code you can do this with GM lite.
Note: Doesn't work with animated sprites unless you find a way, if you do post it.
First make your sprite rotate 360 degrees in 22 frames. Make sure the first frame faces right.
Then in the step event for that object have this code:
image_single=(point_direction(x,y,mouse_x,mouse_y))/360*22
If it's not good enough make the sprite rotate in 360 degrees in 45 frames or 90. If you do change the 22 in the code to however many frames are in the sprite.
Note: If you use too many frames the game will be slow and stupid.
Hopefully you use this well and make your games that little bit better, no need to give credit if you use it.
Note: Doesn't work with animated sprites unless you find a way, if you do post it.
First make your sprite rotate 360 degrees in 22 frames. Make sure the first frame faces right.
Then in the step event for that object have this code:
image_single=(point_direction(x,y,mouse_x,mouse_y))/360*22
If it's not good enough make the sprite rotate in 360 degrees in 45 frames or 90. If you do change the 22 in the code to however many frames are in the sprite.
Note: If you use too many frames the game will be slow and stupid.
Hopefully you use this well and make your games that little bit better, no need to give credit if you use it.
Js. do not missuse mod privilages.
cool!
Just make the animation 22 frames and then go into animation on the sprite editor select rotate counter clockwise (or clockwise) and 360 * and 22 frames.
Just make the animation 22 frames and then go into animation on the sprite editor select rotate counter clockwise (or clockwise) and 360 * and 22 frames.
Last edited by 3d on Thu Jun 04, 2009 3:57 pm; edited 1 time in total (Reason for editing : Js used mod privilages wrongly)
Re: Point to mouse with lite.
Thanks carinivorous! That is a great piece of code. I just might add that in my tutorial with credit to you as creator
Re: Point to mouse with lite.
JS! if you edit someones post, who doesnt need to be editted, OR if its me your editting i will remove ur mod privliages.
Re: Point to mouse with lite.
You can make 360 degrees to; in the first sprite editor, when you click on Edit Sprite, you can click on Animation + Rotation Sequence + Counter-Clockwise.
Then you have to enter 360 as Number of Frames and 360 as Degrees.
Then, in the Step event of your object, you just have to put :
image_index=point_direction(x,y,mouse_x,mouse_y)
Hope that'll help!
Then you have to enter 360 as Number of Frames and 360 as Degrees.
Then, in the Step event of your object, you just have to put :
image_index=point_direction(x,y,mouse_x,mouse_y)
Hope that'll help!
Re: Point to mouse with lite.
Yeah but that code is Pro only. Its good but this is helpful because its for Lite.
Re: Point to mouse with lite.
Pro? I though it was Lite...let me see...
No! Nothing Pro inside that code!
No! Nothing Pro inside that code!
Re: Point to mouse with lite.
I did that once, it goes ridiculously slow.Wiialex8 wrote:You can make 360 degrees to
Re: Point to mouse with lite.
The best solution to rotations, is this:
direction = point_direction(x, y, mouse_x, mouse_y)
image_index = image_number * direction/360
This allows you to have ANY number of sub-images, and it will still work. I recommend 36 or 24 sub-images. Also, if you want animated sprites, here's how you can do this:
Make a new sprite, this contains frame two, repeat as many times as necessary to get all the frames in the animation. Rotate them all anti-clockwise. They should all have the same number of sub-images.
Next step, head over to the object create event, and place this code:
current_frame = 0;
image_frame[0] = 2; // Number of frames
image_frame[1] = spr_frame_1; // Frame 1
image_frame[2]= spr_frame_2; // Frame 2
frame_speed = 1; // Speed of the animation
In the step event, place this code
current_frame += frame_speed;
while (current_frame > image_frame[0]) {current_frame -= image_frame[0];}
In the draw event, place this code:
draw_sprite(image_frame[current_frame], image_index, x, y);
And that should do the job
direction = point_direction(x, y, mouse_x, mouse_y)
image_index = image_number * direction/360
This allows you to have ANY number of sub-images, and it will still work. I recommend 36 or 24 sub-images. Also, if you want animated sprites, here's how you can do this:
Make a new sprite, this contains frame two, repeat as many times as necessary to get all the frames in the animation. Rotate them all anti-clockwise. They should all have the same number of sub-images.
Next step, head over to the object create event, and place this code:
current_frame = 0;
image_frame[0] = 2; // Number of frames
image_frame[1] = spr_frame_1; // Frame 1
image_frame[2]= spr_frame_2; // Frame 2
frame_speed = 1; // Speed of the animation
In the step event, place this code
current_frame += frame_speed;
while (current_frame > image_frame[0]) {current_frame -= image_frame[0];}
In the draw event, place this code:
draw_sprite(image_frame[current_frame], image_index, x, y);
And that should do the job
Hepolite- GameML Noob
- Posts : 23
Points : 54587
GameML Reputation : 12
Join date : 2009-06-03
Age : 31
Location : Land far, far away from the land far, far awaay
Re: Point to mouse with lite.
Making direction equal point_to_mouse probably won't let the object move properly, because direction is already a variable for which direction the object is moving in.
Similar topics
» Simple 2D Rain Code-Lite
» MOUSE controlled 3D games!
» The point of GML
» turn object to a point
» Finding a point relative to the x, y, and z angle?
» MOUSE controlled 3D games!
» The point of GML
» turn object to a point
» Finding a point relative to the x, y, and z angle?
:: Game Making :: Game Maker Help :: Game Dev. Q&A :: GML help (Coding)
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum
|
|