GameMaker: Studio > 一般討論 > 主題細節
*COZ* Pfc315 2012 年 10 月 4 日 @ 上午 11 時 42 分
Tutorial 2 Particales: Code
Well on page 2 of the tutorial it says to Create a new object and assign it the button sprite indexed as "spr_Button_BuiltIn" and name the object itself "obj_Button_Builtin", then add a Create Event and in it place the following code:

Well I did everything right up to createing the event but im not sure how to put the code in where am I suposed to place? Or do I have to make a action???
顯示 1-11,共 11 則回應
< >
M.S.T.O.P. 2012 年 10 月 4 日 @ 下午 12 時 43 分 
There is an action called "Execute Code". It's in the Control tab, under the "Code" section and looks like a white sheet of paper.
*COZ* Pfc315 2012 年 10 月 4 日 @ 下午 1 時 27 分 
Thank you the tutorial wasn't being that clear. but im still having problems because this tutorial sucks. any know of any videos on this tutorial?
MattchuDeePorkupineh 2012 年 10 月 4 日 @ 下午 1 時 48 分 
With the exception of a few deprecated functions, most GM8 and GM8.1 video tutorials on Youtube should be more or less compatible with GMS, so if you need a video tutorial that's similar to that one, but maybe not exactly the same, check Youtube for similar ones for GM8/8.1.

There is quite a bit of new stuff in GMS that won't be covered, but it should teach you GML well enough to manage on just using the help file's documentation.
*COZ* Pfc315 2012 年 10 月 4 日 @ 下午 2 時 25 分 
Ya it just seems that this tutorial is very vague.
MattchuDeePorkupineh 2012 年 10 月 4 日 @ 下午 2 時 38 分 
It might be.

But yeah, search Youtube. Should be easy to find something.
最後修改者:MattchuDeePorkupineh; 2012 年 10 月 4 日 @ 下午 2 時 38 分
*COZ* Pfc315 2012 年 10 月 4 日 @ 下午 5 時 00 分 
Ok so here is the problem so you know where im stuck. This where im at in the tutorial 2 particles.

The code above that we place in this alarm will be used to reset the image index (current sub-image chosen) of the sprite to 0, and in this way we can create a "hover" and "pressed" state, then set this alarm to reset the button back to a "normal" state. This will be done by the following code, which is where we check the mouse position, check to see if the mouse has been pressed, and then create the firework object itself:



if instance_position(mouse_x, mouse_y, id)
{
if image_index < 2
{
image_index = 1;
if mouse_check_button_pressed(mb_left)
{
alarm[0] = room_speed / 2;
image_index = 2;
instance_create(random(room_width), 400, obj_BuiltIn_Firework);
}
}
}
else
{
if image_index < 2
{
image_index =0;
}
}


So, that code will check to see if the mouse position coincides with the button mask, and if it does it checks the current button image_index and sets it to "hover" state if it has not been pressed. It then detects any mouse presses and if there is one, it sets the image-index to 2 ("pressed" state"), sets alarm[0] to reset the state which permits it to be pressed again, and creates an instance of the object "obj_BuiltIn_Firework" at a random position along the x-axis.


I can not figure out where to put that code when i run the game it launches 1 firework off to the right without me doing anything. but i also have zero effect on anything in the game.

PS: This is on page 2 of the tutorial.


EDIT: The code did not paste like it looks in my game.
最後修改者:*COZ* Pfc315; 2012 年 10 月 4 日 @ 下午 5 時 01 分
MattchuDeePorkupineh 2012 年 10 月 4 日 @ 下午 5 時 04 分 
Since that has "if mouse_check_button_pressed", I'd assume that it should go into the step event of the appropriate object.

Just checked the tutorial and even though it doesn't explicitly say it, I'd assume you put it in obj_BuiltIn_Firework's Step event.
*COZ* Pfc315 2012 年 10 月 4 日 @ 下午 5 時 40 分 
In what event though because I think there is suposed to be 4 events in obj_BulitIn_Firework
MattchuDeePorkupineh 2012 年 10 月 4 日 @ 下午 7 時 02 分 
The Step event, hence "I'd assume it should go into the step event of the appropriate object."
*COZ* Pfc315 2012 年 10 月 4 日 @ 下午 7 時 40 分 
I sent you a friend request if you could add me mattchu it would be alot easier to do this.
*COZ* Pfc315 2012 年 10 月 4 日 @ 下午 8 時 12 分 
Got it dont use alram for builtin button use step and place the code in there.
顯示 1-11,共 11 則回應
< >
每頁: 15 30 50
張貼日期: 2012 年 10 月 4 日 @ 上午 11 時 42 分
回覆: 11