game maker create object outside view

Press J to jump to the feed. Press question mark to learn the rest of the keyboard shortcuts

log in sign up Visit Old Reddit


Posts Subreddit Guidelines Minimap

Feedback Friday Screenshot Saturday Quick Questions Game Design & Dev
Discord Server Slack Team IRC Twitter YoYo GMC
Resources Examples Tutorials GMLScripts


Posted byu/[deleted] 2 years ago

How to make objects outside of the camera (or view if you will) deactivate or destroy.

I've tried a few methods how to do this but they either don't work or causes ALL of the bullets to deactivate and I can't shoot anymore. In case if your wondering, I'm making a binding of issac esque game and was wonding how to stop this from happening.


100% Upvoted
This thread is archived
New comments cannot be posted and votes cannot be cast
Sort by

level 1


1 point · 2 years ago

What have you tried?

There is an event for "outside view" under "other", you could put a destroy action there, or you could do math to check its location, and determine if it is outside of the camera on step.

level 2


1 point · 2 years ago

Yep. I knew about the outside view event. If I leave the first room I lose my ability to shoot.

I tried doing code but I got a similar result.

level 3


1 point · 2 years ago

I would need to know more about how your system works then, but assuming bullets are their own entity, you just need to put an outside view event on the bullet object that just runs instance_destroy() on it.

level 4


1 point · 2 years ago

I used Shawn Spalding's sliding camera tutorial. I adjusted it a bit because of a glitch because I think my view size was much larger

/// Position the View
var xTo, yTo;
if instance_exists(obj_player)
xTo = (obj_player.x div view_wview[0])*view_wview[0]
yTo = (obj_player.y div view_hview[0])*view_hview[0]
var difX, difY;
difX = (xTo*1.5 - x)
difY = (yTo*1.5 - y)
if (abs(difX) < 1) x = xTo*1.5; else x += difX/10;
if (abs(difY) < 1) y = yTo*1.5; else y += difY/10;
view_xview[0] = x;
view_xview[0] = y;

If I didn't add the *1.5 the view only slides halfway for some reason.

level 5


1 point · 2 years ago

Ah, so you are using the term "room" to mean a subsection of the game room, displayed by a view. I thought you meant the actual room.

Anyway, try this:

On your bullet object, in the step event:

// If this is outside of the current view, destroy self
if (x < view_xview || y > view_yview || x > view_xview + view_wview || y > view_yview + view_hview) instance_destroy();

I guess I still don't know why your bullet object's "outside view" event wouldn't work, but again, without knowing more about how you have things set up, I can't help as much. Sounds like theres deeper issues if you can't just destroy the bullet object when it is outside of the view.

Be sure you're using the right view number, by the way. view_xview and those variables default to view0.

level 6


1 point · 2 years ago · edited 2 years ago

Same Results. Every time I leave the "sub_room" I no longer can shoot.

Be sure you're using the right view number, by the way. view_xview and those variables default to view0.

It's on view0

sounds like theres deeper issues if you can't just destroy the bullet object when it is outside of the view.

basically I have a global left click event that creates obj_projectile. Inside the projectile create event:

move_towards_point(mouse_x, mouse_y, 12);

And an alarm that makes sure my game doesn't become a bullet hell.


I feel like maybe the view itself isn't moving somehow. Is there a way to fix this?

level 1


1 point · 2 years ago

Below is a bit of code that I used to deactivate all objects just outside of the camera view. Additionally, I had to also overcome an issue with enemies falling thru the floor so I did it in 2 steps. The first re-enables all solids at a slightly larger range then it re-enables the physical entities in a slightly smaller range, all of which still occurs slightly outside of the camera view.

I'm rather new at this and there is probably a better way but this is what I got working for me. My game is just a side scrolling platformer with gravity so you may only need just 1 step for your code.

 instance_deactivate_all(true);//turn off everything instance_activate_region(v_xv, v_yv, v_wv, v_hv, true);//keep hud and other controls active instance_activate_region(view_xview[0] -256, view_yview -256, view_wview[0] + 512, view_hview + 512, true);//static big view //then deactivate all physic entities, things that can fall thru floor instance_deactivate_object(objEnemy);//Deactivate enemies instance_deactivate_object(objItem);//Deactivate Items instance_deactivate_object(objBigBlock);//Deactivate moving blocks instance_deactivate_object(objCrushingBlock);//Deactivate moving blocks instance_activate_region(view_xview[0] - 128, view_yview - 128, view_wview[0] +256, view_hview +256, true);//re-enable all physical entities

I know I came across a few examples that didn't really work for me when I wanted to use this method of optimization so maybe this won't work for you. But maybe you'll get something out of it or at least get you going in the right direction.

Community Details






This subreddit is dedicated to the game development platform, GameMaker Studio. GameMaker Studio is designed to make developing games fun and easy. It features a unique "Drag-and-Drop" system which allows non-programmers to make simple games. Additionally, experienced coders can take advantage of its built in scripting language, "GML" to design and create fully-featured, professional grade games.

Create Post
r/gamemaker Rules
Content must be directly related to GameMaker
Content must be in English
No obscene, illegal, racist or offensive content
No "click-bait", shortened links, or solicitation
Content must show previous effort and full detail
Have respect and patience
Promotional content must be a contribution
Tech support requests go to YoYo Games Support
Content must be appropriately flaired

For more than 8 years, the tight-knit community of /r/gamemaker has run the game jam gm(48) for GameMaker developers of all ages and experience levels. The gm(48) is a casual, fun game jam that helps you to learn and grow as a developer.

The next gm(48) will take place on April 13th, 2018.

Scheduled content
Monday Quick Questions Ask questions, ask for assistance or ask about something else entirely.
Wednesday Game Design & Development Discuss game design and game development.
Friday Feedback Friday Play games and lend feedback
Saturday Screenshot Saturday Share the latest pictures and videos of your game
Monthly Monthly Challenge Are you in need of motivation? Then take a stab at these creative challenges.

/r/gamemaker sponsors three chat-rooms: IRC , a Discord server , and a Slack team . Join in the conversation, get help with any issues you might have and connect with your fellow developers!

about careers press
advertise blog help
the reddit app reddit gold reddit gifts
content policy | privacy policy
user agreement | mod policy
© 2018 Reddit, Inc. All rights reserved