how to allow an object to move through gaps in an skphysicsnode - ios

I want to try to have a sprite kit node move through this image and when it contacts one of the blocks it executes a function and is blocked from moving forward, but it can pass through the gaps. The way my code is set up now however, the entire image is recognized as one node so nothing can pass through even the gaps. I was wondering if anyone had some suggestions on how to work around this without having to add each individual block as its own node. Thanks.

Sorry to disappoint you but what you want to do is not possible. I know of 2 ways to detect collisions.
1) through physics like you are already doing
2) through use of intersects(_:)
Both of them require you to have separate objects. Else how is the system supposed to know the difference between the space in-between the objects and the objects them selves. Your saying you want one massive object. Maybe you could write some great script that detects intersection of different colours, but that would be a really strange solution to a simple problem
Like Steve asked. Why do you not want to add them individually? It's really easy to do. Just create an instance of the object then add it multiple times with different positions. If you are not sure how to do this then, this is the question you need to be asking.

Related

How would you go about creating a random spawner for coins within a certain area? It has to re-spawn coins after the player has collected enough too

I have a coin which rotates and changes size so far. I want to be able to set an area (which is not a nice square of course) that they can randomly spawn locations. The thing it has to do is once there are less that 7 coins then it spawns more.
Anyone able to give me some advice? Not sure what is most efficient method.
It sounds like you should be making use of ZonePlus and its getRandomPoint function.
If you want a direct reference, the creator of the module made a playground and its source code is publicly viewable. The playground contains a 'CoinSpawner' (literally what you're looking for).
You can either make use of "Region3" or you can set up multiple possible spawn points and run a math.random function to choose which one.

How can I remove sprites when they are outside viewport, but then add them again if I return to their location to save memory

I'm creating an open-world RPG like Neverwinter nights. But I'm worried about memory and am afraid if I just populate a huge world with physics-based sprite nodes, I won't have any memory for anything else.
To combat this, I want to remove the sprites when they go far outside of the viewport and then re-add those sprites when I get close to their location.
How could I accomplish this?
To any and all who take time to help me with this, thank you!
You can store all data on a database like CoreData with exact parameters you need like states and positions whatever do you need.
Then you can create a method to get all objects on a specific position with radius and use this method when the player moves or when you need to check things like a quest on another site, take those objects and compare with current objects, place again on the correct site the new ones and remove the old ones (they are not on radius probably or disappears for another reason)
This is a complex approach but it could work.

Deflod rendering issue

I am going to make simple 2D game in Defold game engine and I am new in this area. My question is, I have 2 game objects every object has sprites in it. A sprite in the first game object must be background for sprites of second object. I have designed it well but when I run (or render, I don't know how to call properly) it sometimes sprites of second game object are invisible and some times everything is OK.
The same issue if I set main backgruon image for the game. Please share your experiences with me. Thanks beforehand.
You posted the same question on the official Defold forum so I'm going to replicate the answer you got there here on SO as well. The solution is to make sure that the depth of two game objects that overlap isn't the same. If two objects have the same depth and overlap you might sometimes see one in front of the other and sometimes vice versa. The default render script allows a z-range of -1 to 1 (you can use fractional z-values to get fine grained control), but you can copy it from builtins and increase the range if you want to. Something like -10 to 10 is usually a good enough value.

Memory Usage of SKSpriteNodes

I'm making a tile-based adventure game in iOS. Currently my level data is stored in a 100x100 array. I'm considering two approaches for displaying my level data. The easiest approach would be to make an SKSpriteNode for each tile. However, I'm wondering if an iOS device has enough memory for 10,000 nodes. If not I can always create and delete nodes from the level data as needed.
I know this is meant to work with Tiled, but the code in there might help you optimize what you are looking to do. I have done my best to optimize for big maps like the one you are making. The big thing to look at is more so how you are creating textures I know that has been a big killer in the past.
Swift
https://github.com/SpriteKitAlliance/SKATiledMap
Object-C
https://github.com/SpriteKitAlliance/SKAToolKit
Both are designed to load in a JSON string too so there is a chance you could still generate random maps without having to use the Tiled Editor as long as you match the expected format.
Also you may want to consider looking at how culling works in the Objective-C version as we found more recently removing nodes from the parent has really optimized performance on iOS 9.
Hopefully you find some of that helpful and if you have any questions feel free to email me.
Edit
Another option would be to look at Object Pooling. The core concept is to create only sprites you need to display and when you are done store them in a collection of sorts. When you need a new sprite you ask the collection for one and if it doesn't have one you create a new one.
For example you need a grass tile and you ask for one and it doesn't have one that has been already created that is waiting to be used so it creates one. You may do this to fill a 9 x 7 grid to fill up your screen. As you move away grass that gets moved off screen gets tossed into the collection to be used again when the new row comes in and needs grass. This works really well if all you are doing is displaying tiles. Not so great if tiles have dynamic properties that need to be updated and are unique in nature.
Here is a great link even if it is for Unity =)
https://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/object-pooling

collision detection and creation in xcode class

I'm working on making a new app in xcode and have run into two problems that always seem to be a problem when I program large projects.
Basically, I want the user of this app to be able to input specifics like size, position, color, and possibly speed and/or direction.
These inputs will create a square of specific size, position, and color which will move around the screen and interact with other squares the user has created.
Now here are my problems:
First: I have absolutely no idea how to create something in code. I know I almost certainly have to do this in a class, but I've never figured out how to do this in a single programming language.
Second: Interaction between the squares. How do I detect collisions between the possibly dozens or hundreds of squares the user creates.
I'd really like to figure out how to do this, especially because I'm sure it'll be helpful in not only this, but many other future projects.
Thanks
I would recommend using sprite kit for the collision detection and creation of the squares. You'll probably want to subclass SKSpriteNode to define the properties for your squares.
https://developer.apple.com/library/ios/documentation/GraphicsAnimation/Conceptual/SpriteKit_PG/Introduction/Introduction.html

Resources