Is there any way I can make it so every time I add a particular image/sprite to the scene in the Scene Editor it can be assigned a Custom Class?
I am trying to make a game with a lot of sprites, and it is a hassle to assign Custom Classes to each sprite.
I know I can multi-select sprites and assign them the same Custom Class, but default Custom Classes would be so much easier.
Related
A SKScene (.swift file) object can be can be loaded with any scene (.sks) file. This allows you to create mulitple .sks files and load any of them with the same SkScene object. GameScene.swift for example could be instantiated with Level_1.sks or Level_2.sks. Any ideas on how to accomplish this?
I'm not sure if this is the correct approach to make multiple levels, but if you wanna reach this goal simple put in your scene editor with the Scene select click on Custom Class Inspector and write the class name you want (GameScene for example)
So I have objects that in turn have sprites associated to them. a snippet of my Object class:
import SpriteKit
class Block {
var sprite : ColourSprite
}
So as you can see, it has a variable that is in fact a SKSprite (ColourSprite is my custom class that inherits from SKSpriteNode).
Now, at some points during the game, these sprites are deleted (i.e sprite.removeFromParent()), but the objects are obviously still somewhere.
I want to be able to send the objects to garbage collection once their sprites are gone. I am thinking that I can do something like sprite.getOwner() but I can't seem to find it. Is this possible?
The only other option I can think of is to manually check all objects and check each one's sprite but I feel that is long and wasteful.
You can check whether the Blocks are still in memory by using Xcode 8.3's new debug panel.
Just after you remove your sprites pause the program and go to that panel. See if there is any Block instances in the left panel. If there is, click on it to check what is retaining it.
If for example your GameScene is retaining the Block, you go to your GameScene and find the property. Then you can just set that to nil after you remove your sprite.
Because of the fact that SpriteKit does not support custom drawing on SKNodes, I have to create a custom sprite node and add other nodes to it.
When I am adding other nodes to the parent node, the coordinate system of the parent view is really confusing me. I always have to try a lot of times to get the node to the place where I want it to be. Sometimes I can't even see the node added.
I think this is very annoying. I think SpriteKit must provide some way to let me "design" a custom node in a graphical way. I want something like the SKScene designer. But instead of designing a scene, I can design a node. After that, I can reuse the designed node in code, just like I can reuse table view cells that are already designed in IB.
Is there something like that in Xcode?
The coordinate system is really easy to understand, when you place a node inside another node, the coordinates become relative to parent, not the scene.
Since SKScenes are SKNodes, you can use the sks file to design your nodes on a per node basis and load an sks for every node you need, or you can create several nodes inside 1 SKScene file, and just extract them from the sks during your loading phase.
I've recently started developing an iOS app, which I've never done before, so it's been going a bit slow, but I'm learning, so that's understandable.
I want to make a custom interface, so I've been making subclasses of the default view classes (like UIButton) so that I can define custom drawing. I've been told this is the best way to define custom interface elements that can be reusable. It definitely seems to be working that way. However, I haven't been able to make elements completely reusable by just using a subclass.
For example, in order to prevent a button's text from changing color when it is clicked, I have to manually go into the interface builder and set the button type to "Custom." After that, code that I enter into the subclass's constructor to change attributes seems to work. But I have to do this for every button I add, and in code the "buttonType" attribute is read only. Is there a way for me to define (just once) certain attributes for every instance of my button subclass that I add to the interface?
My goal is to be able to have a button subclass or template that defines all attribute values that I want my buttons to have, and every instance that I add automatically reflects those properties without me having to change anything. More so, I want to be able to modify that subclass/template and have those changes reflected in every existing instance. I have to imagine that this is possible in iOS. There is simply no way to build sophisticated interfaces without this capability.
Define a custom Button class (inherited from UIButton) in your project and in the init set the properties which you wanted to be set across.
In the interface builder go to the the class inspector and enter the button to be of the previously declared button.
buttonType needs to be set for all the button as this is defined at initialization time and exposed as read only property. If you want absolute reusability for your case, create a view, with an embedded button in code. when you create a button, create using the static method buttonWithType.
Wherever you need, drag and drop a UIView and set the view type to be the custom view.
I want to make a group of cocoa touch objects behave like one object, Is this possible?
For instance, say we had a SuperButton that consisted of two UIButtons, spaced by 10.
Let's just say their frame is set.
Is it possible to make a wrapper class ?
that I can init and call -
[_view addSubview:SuperButton] on and have it create both buttons?
I'm not entirely sure on the terminology for what I'm trying to do so it's hard to find any help on google.
Okay, Let me ask you this question first. So you want to create a SuperButton, when ever you call it it should layout the two buttons for you, is this right ?. YES you can do this. Create a new XIB, which is having just a view. configure your buttons in it. Create your super button class and assign it to this xib. You should be able to call this class and it will return view which can be added to your main view controller.