Legacy GM how to make a solid surface (physic) without sprite index?

Bhreno

Member
It's possible?
In my game, obj_ball collides with a "scratch" created by the mouse (a surface), and deflects. However, I can't make this surface solid enough that obj_ball detects any collision with it.
 

Attachments

You could use place_meeting()
If you want a system for deflection you could use this

if(place_meeting(x,y,object))
{
if(direction>=0)
{
direction = -direction;
}
if(direction<=0)
{
direction = direction;
}
}
 

TailBit

Member
use:
sprite_create_from_surface(index, x, y, w, h, removeback, smooth, xorig, yorig);
and set it as a object's sprite_index ..

Just keep in mind that this could cause memory leak if you keep creating sprites without destroying them at some point.
 

Bhreno

Member
use:
sprite_create_from_surface(index, x, y, w, h, removeback, smooth, xorig, yorig);
and set it as a object's sprite_index ..

Just keep in mind that this could cause memory leak if you keep creating sprites without destroying them at some point.
I did that, but the obj_ball still don't detect any collision with obj_surface.

The "surface" of obj_surface is created from the mouse click and its codes are:

IN CREATE:
Code:
surface = surface_create(room_width, room_height);
spr_custom = sprite_create_from_surface (surface, 0, 0, 10, 10, false, false, 5, 5);
sprite_index = spr_custom;
mx=0;
my=0;
alarm[0]=120;
IN DESTROY:
Code:
surface_free (surface);
sprite_delete(spr_custom);
if point_limit == false
{
if point < 20
{
point +=1;
}
}
IN ALARM [0]
Code:
instance_destroy();
IN STEP EVENT:
Code:
mx=mouse_x;
my=mouse_y;
IN GLOBAL MOUSE LEFT BUTTOM
Code:
surface_set_target(surface);
draw_set_color(c_black);
draw_circle(mouse_x,mouse_y,5,false);
draw_line_width(mouse_x,mouse_y,mx,my, 10);
sprite_add_from_surface(spr_custom, surface, mouse_x, mouse_y, mx, my, false, false);
surface_reset_target();
IN DRAW EVENT:
Code:
if surface_exists(surface)
{
draw_surface(surface, 0, 0);
}
And in the collision with obj_ball, has "instance_destroy".
The obj_surface is physic e no have sprite (only spr_custom);
 

TailBit

Member
You created it when the surface was empty .. so ofc there won't be any collisions, delete sprite and create a updated one after drawing is done:

in global mouse left release, or at the end of the current mouse event if you want it to happen right away..
Code:
sprite_delete(sprite_index);
sprite_index = sprite_create_from_surface (surface, 0, 0, 10, 10, false, false, 5, 5);
spr_custom = sprite_index;
Any reason you made the spr_custom? Didn't deleting it directly from sprite_index work?
 

Catastrophe

Member
The obj_surface is physic e no have sprite (only spr_custom);

^by "physics e" you don't mean physics enabled do you? Because a sprite index isn't going to do anything for physics I think, you'll need a fixture. Not that you'd want physics enabled probably, I just don't understand what is being said here and wanted to clarify

What is the collision code for the ball/surface, like what actually is used to detect collisions (place_meeting, collision event, etc)?

I would also not draw your surface to the screen after you have set your sprite_index, just to make sure have correctly attached the actual sprite to the object. If you don't see anything, your obj_surface did not transfer the sprite correctly.



Additionally, if you read the manual on sprite_create_from_surface it's going to create your bounding box for collisions automatically. Since you have a curve you will want to use sprite_collision_mask and set it to precise collisions

Finally, google "destructible terrain tutorials game maker" and these should give you general guidance on this method, you might figure things out yourself without additional help if you check those out. Technically it's the opposite since you're adding, but the same principles will apply

Edit: oh duh, you need draw_self() in your draw event
 
Last edited:
Top