GameMaker: Studio

GameMaker: Studio

查看统计:
Hoonster 2015 年 3 月 19 日 上午 7:28
Problem with instance_place() function.
Starting a new thread.
To cut to chase, instance_place() is not working. I used

first = instance_place(x,y,Obj_ele);

However, first.x and first.y is placed at 0,0 even though the object is in the middle of the screen. I have removed all of my codes except to test instance_place function. There is absolutely no way that other codes are interfering.

This is way too frustrating. I decided to give up and tried to use object_set_parent() by rolling back to earlier version of GameMaker. Except object_set_parent() seems to be obsolete in all versions. Grrrgh . . .
< >
正在显示第 1 - 8 条,共 8 条留言
Blind 2015 年 3 月 19 日 下午 3:12 
first is local to the event creating the Obj_ele
Hoonster 2015 年 3 月 19 日 下午 5:24 
I have tried labeling 'first' as global variable and local variable. first.x and first.y always came out as 0,0.
Daynar 2015 年 3 月 19 日 下午 7:26 
Alright just created a demo to test and it works for me.
First thing you should be aware of is that instance_place() is a special collision test. It checks for a collision between the calling objects collision mask and the specified objects collision mask if the calling object were at a speicifc location. Therefore both objects require a collision mask and to exist in the first place. If you're already aware of this and it's still not working I'll be happy to upload the code in the demo I made to test it.
Hoonster 2015 年 3 月 19 日 下午 9:32 
引用自 Daynar
Alright just created a demo to test and it works for me.
First thing you should be aware of is that instance_place() is a special collision test. It checks for a collision between the calling objects collision mask and the specified objects collision mask if the calling object were at a speicifc location. Therefore both objects require a collision mask and to exist in the first place. If you're already aware of this and it's still not working I'll be happy to upload the code in the demo I made to test it.

It seems quite clear that I am using the function incorrectly as I am not entirely sure what you mean by special collision test. Do I have to enable collision check in order for the function to work properly? Since my code is fairly simple, I will simply write the entire code here.

Currently I have 2 'Obj_ele's in an empty room.

My code locaded in step event in Obj_ele is as follows :

if mouse_button_check(mb_left)
{
if abs(x-mouse_x)<=32 && abs(y-mouse_y)<=32
{
if select = 0 && global.selection = 0
{
global.first = instance_place(x,y,Obj_ele);
select = 1;
global.selection = 1;
}
if select = 0 && global.selection = 1
{
global.second = instance_place(x,y,Obj_ele);
select = 1;
global.selection = 2;
}
}
}

if first != 0
{
instance_create(first.x, first.y, Obj_test);
}
if second != 0
{
instance_create(second.x, second.y, Obj_test);
}

I used this to test instance_place function. Whenever I click on the Obj_ele, Obj_test does appear in the screen, but on (0,0) location rather than the appropriate location.
Daynar 2015 年 3 月 19 日 下午 9:46 
Found you're problem you used global.first and global.second in the first code bit then first/second in the next code bit. You can fix this by simply adding the global. prefix to when you reference first/second later are.
Hoonster 2015 年 3 月 19 日 下午 10:49 
引用自 Daynar
Found you're problem you used global.first and global.second in the first code bit then first/second in the next code bit. You can fix this by simply adding the global. prefix to when you reference first/second later are.

I am sorry, I didn't literally copy paste the codes. I declared first and second global variables through globalvar first; and globalvar second;
Hoonster 2015 年 3 月 20 日 上午 1:26 
I think the problem was that I didn't set the collision mask. I looked up in the game maker and kind of understand what I have to do now. I will try this tonight. Thank you so much for your help!
Hoonster 2015 年 3 月 22 日 上午 1:14 
引用自 Daynar
Alright just created a demo to test and it works for me.
First thing you should be aware of is that instance_place() is a special collision test. It checks for a collision between the calling objects collision mask and the specified objects collision mask if the calling object were at a speicifc location. Therefore both objects require a collision mask and to exist in the first place. If you're already aware of this and it's still not working I'll be happy to upload the code in the demo I made to test it.

Would it be possible to upload the code? I have tried everything and it simply isn't working. I don't understand the problem at this point.

Thank you so much for helping me.
最后由 Hoonster 编辑于; 2015 年 3 月 22 日 上午 1:14
< >
正在显示第 1 - 8 条,共 8 条留言
每页显示数: 1530 50

发帖日期: 2015 年 3 月 19 日 上午 7:28
回复数: 8