GML: instance_create not working, object is not being put into the room - game-development

I'm trying to make a game where spikes fall from the sky and the player has to move from side to side to dodge them. The object I'm trying to get to move down from the top of the screen is named obj_spike. What I want to accomplish is the spikes spawning in at the top of the screen and moving downwards. This works if I put the objects in the room as they are, but I can't make it spawn infinitely. How do I do that? The piece of code I've been trying to use is this:
instance_create(random_range(0,640),480,obj_spike);
For some reason the object just doesn't create.

Related

Im having problems with the collisions im GMS2 using GML

Theoretically, when I touched an enemy I would lose one life and from three hearts I would have 2. What happens is that when I collide with him, the lives are all lost restarting the room because I have to when I reach 0 lives, the room restarts. I'm using GMS2 and using GML, I don't know anything about DnD... HereĀ“s my code to collision with enemy:
//create event
global.lifes = 3
//collision event
global.lifes -= 1
You'll need to implement an invulnerability function, that'll prevent the player character from getting damaged again on the next frame.
The most simple one would be a timer that counts down if you got hit, and if that timer is still counting down, then ignore the Collission Event.
See also my answer here about adding invincibility in GMS2:
https://stackoverflow.com/a/62769522/2735344

No keyframes are visible but the object still moves

I'm using Blender 2.8 and I just have 2 objects: hand and gun and I want to create animations for them. So, for instance, I want to create a simple firing animation. What I do:
1. I create animation for gun
2. I create animation for hand
But if I switch somehow incorrectly I "lose" the first animation I've created. I tried creating fake users and stuff. I just don't get why I select the armature for which I've just created the animation, it plays, but there are no keyframes.
Here's the vid, here's the file.
Ask me questions if you have any.
The movement may be cached in Blender, you may need to reset the movement cache.
Alternatively, you should look at both the Track Controller and Dopesheet(action editor) - the animation may be stored in both.
The movement could be related to parenting ( to an object that is moving )
The movement could also be caused by physics simulation of a rigid body.
Hopefully with the help of the above, you find the problem.
I had the same problem. In the Animation mode (horizontal tabs across the top of the window), click on the object to animate.
The keyframes will appear.
If the object is not selected, the keyframes disappear.
Just leaving this here so that nobody spends 30 minutes trying to work this out, like i just did.

Adding many actors to the stage

I crating project to play with some sort of simulation. So i create map, this map is actually grid with cells, each cell is 2 actors - 1 background and 1 icon that show cell type - forest, mountain, person and etc.
Here how it looks:
All works just fine, but when i try to increase cells from 20x20 to 100x100 it takes about 20-30 seconds to load. It doesn't seems lags after it loads, so it works just fine, but now question - is there a way to optimize loading time, or it impossible?
Todays systems should be able to handle as little as 100x100 cells. I guess your problem is somewhere in your code.
Some common mistakes are:
Creating new objects in your render method (with the "new" keyword) instead of reusing your objects
Loading your images everytime you render them
Maybe you can add some code of your render method to the question. Without any code it's hard to see the problem.

How I can I delete sprites without obstructing the physics in SpriteKit?

I want to make a game in which sprites fall from the sky and stack up on the floor, however when there is a lot of layers the camera will move up so you can continue playing. After a while more and more rows of sprites will become invisible as the camera moves up. I want to delete these unused sprite-nodes to keep the performance as good as possible. But when I delete the nodes at the bottom of the stack, won't the entire thing collapse? Or should I detect when the bottom row is unused and then turn off physics for the row above it so it wont fall down and won't affect the rows above it or something of that nature.
I haven't actually made any code yet, I just wanna have a good idea of what I'm doing before I start the wrong way.
Yeah I totally agree, you would really have to be clever about it. Well setting the background image coordinates and looping the background for a "continuous scroll effect" would be Step NO.1 Then using particle physics or actually rendering Nodes would be Step NO.2 The tricky part like you said would be getting the ones below the scene to be destroyed, but I think that if you try and set boundaries, and maybe an if statement that runs the destruction of the particles below the boundaries. So the particles fall down slowly pile up but as the scene scrolls upwards the particles will be destroyed when the their anchor point goes below the x,y boundaries you set and thus keeping those still visible in the scene alive... That would be my way of going about it.

How to code a random movement in limited area

I have a limited area (screen) populated with a few moving objects (3-20 of them, so it's not like 10.000 :). Those objects should be moving with a constant speed and into random direction. But, there are a few limitation to it:
objects shouldn't exit the area - so if it's close to the edge, it should move away from it
objects shouldn't bump onto each other - so when one is close to another one it should move away (but not get too close to different one).
On the image below I have marked the allowed moves in this situation - for example object D shouldn't move straight up, as it would bring it to the "wall".
What I would like to have is a way to move them (one by one). Is there any simple way to achieve it, without too much calculations?
The density of objects in the area would be rather low.
There are a number of ways you might programmatically enforce your desired behavior, given that you have such a small number of objects. However, I'm going to suggest something slightly different.
What if you ran the whole thing as a physics simulation? For instance, you could set up a Box2D world with no gravity, no friction, and perfectly elastic collisions. You could model your enclosed region and populate it with objects that are proportionally larger than their on-screen counterparts so that the on-screen versions never get too close to each other (because the underlying objects in the physics simulation will collide and change direction before that can happen), and assign each object a random initial position and velocity.
Then all you have to do is step the physics simulation, and map its current state into your UI. All the tricky stuff is handled for you, and the result will probably be more believable/realistic than what you would get by trying to come up with your own movement algorithm (or if you wanted it to appear more random and less believable, you could also just periodically apply a random impulse to a random object to keep things changing unpredictably).
You can use the hitTest: method of UIView
UIView* touchedView=[self.superview hitTest:currentOrigin withEvent:nil];
In This method you have to pass the current origin of the ball and in second argument you can pass nil.
that method will return the view with which the ball is hited.
If there is any hit view you just change the direction of the ball.
for border you can set the condition for the frame of the ball if the ball go out of the boundary just change the direction of the ball.