Jump to content


Photo

Make object stay stuck in place in view


  • Please log in to reply
3 replies to this topic

#1 FruitPlusVeggies

FruitPlusVeggies

    GMC Member

  • New Member
  • 238 posts

Posted 09 August 2010 - 08:05 PM

I have four objects.
They are solid objects.
Two of them have a sprite that is 16px in height, and the width is as big as my view width.
The other two have a sprite that is 16px in width, and the height is as big as my view height.

Every step (in the draw event) I place them accordingly as a border around the view.
Just to make it so I dont ever go out of the screen.

The thing im having a problem with is keeping them to stay stuck on the view.
But whenever my player moves around, they tend to move until I stop moving.

I just want them to stick right onto the view, even when the view moves I dont want these objects to move around AT ALL.
It looks as though they bounce around or something.

obj_controller create event
topsolid[0] = instance_create(x,y,obj_topsolid);
topsolid[0].sprite_index = spr_outeredge;
topsolid[0].xx=0; topsolid[0].yy=0;
topsolid[1] = instance_create(x,y,obj_topsolid);
topsolid[1].sprite_index = spr_outeredge;
topsolid[1].xx=0; topsolid[1].yy=0;
topsolid[2] = instance_create(x,y,obj_topsolid);
topsolid[2].sprite_index = spr_outeredge2;
topsolid[2].xx=0; topsolid[2].yy=0;
topsolid[3] = instance_create(x,y,obj_topsolid);
topsolid[3].sprite_index = spr_outeredge2;
topsolid[3].xx=0; topsolid[3].yy=0;

obj_controller draw event
topsolid[0].xx=view_xview[0]; topsolid[0].yy=view_yview[0]-16;
topsolid[1].xx=view_xview[0]; topsolid[1].yy=view_yview[0]+view_hview[0];

topsolid[2].xx=view_xview[0]-16; topsolid[2].yy=view_yview[0];
topsolid[3].xx=view_xview[0]+view_wview[0]; topsolid[3].yy=view_yview[0];

obj_topsolid draw event:
if(variable_local_exists('yy')){
x=xx;
y=yy;
}

draw_sprite(sprite_index,0,x,y);

  • 0

#2 Katuko

Katuko

    GMC Member

  • GMC Member
  • 5690 posts

Posted 09 August 2010 - 11:19 PM

I am unsure as to why you chose to PM me with a link to this topic, but I can tell you that this is a horribly inefficient way of making the object stay within the view. Just do the following:
if (x < view_xview[0])
{ x = view_xview[0]; }
if (x > view_xview[0]+view_wview[0])
{ x = view_xview[0]+view_wview[0]; }

if (y < view_yview[0])
{ y = view_yview[0]; }
if (y > view_yview[0]+view_hview[0])
{ y = view_yview[0]+view_hview[0]; }
If this makes it "jumpy" when passing the edge then modify your movement code to prevent it from moving past the edges in the first place. No objects needed, no arrays.
  • 0

#3 Staggasaurarts

Staggasaurarts

    GMC Member

  • New Member
  • 6 posts

Posted 09 September 2010 - 07:30 PM

im having the samw trouble and everything i try, even the above code, doesnt work. The object just wont stay still until my player stops
  • 0

#4 brianp

brianp

    Brian Prestley

  • GMC Member
  • 111 posts
  • Version:Unknown

Posted 10 September 2010 - 01:44 AM

If you are using them as borders, you do not even need to check if they go off screen. Instead, use the following (assuming all of your origins are upper left:
//top one
x = view_xview[0]
y = view_yview[0]
//right one
x = view_xview[0] + view_wview[0] - 16
y = view_yview[0]
//bottom one
x = view_xview[0]
y = view_yview[0] + view_hview[0] - 16
//left one
x = view_xview[0]
y = view_yview[0]
That way, they will be set to the view's positions without checking if they are off the screen.
Hope this works (and helps)!
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users