levels in xcode spritekit, swift - xcode

I have made some games in Xcode using spritkit(Swift); however, never with levels. I do not really understand how you make different levels in spritekit. It does not seem like a good idea to make different levels in different "GameScenes", or is it? I would really appreciate some help with this. Thanks in advance!

I understand this is very late but I'd like to help future programmers. The way I was taught to add levels in a way similar to how Angry Birds has its levels. What you do is create a new .sks file by going in Xcode to
File => New => File...
When the popup appears select SpriteKit Scene. Save its name to whatever you feel like. At this time, take a break to make your level alone in the new SpriteKit Scene. Here's an example for a game similar to Angry Birds:
[Required] Now, to be precise in where you want the level to be, go to your GameScene.sks file and add a new node to the place you want your level to be. In the Attributes inspector, name the node to levelNode.
Now, go to your GameScene.swift file. Go to the top of the file and add
var levelNode:SKNode!
Then navigate to your didMoveToView function and add the following code to the beginning of it:
levelNode = self.childNodeWithName("levelNode")
After the that line of code, add this:
let resourcePath = NSBundle.mainBundle().pathForResource("WhateverYouNamedYourLevel", ofType: "sks")
let newLevel = SKReferenceNode (URL: NSURL (fileURLWithPath: resourcePath!))
levelNode.addChild(newLevel)
Good Job! You have just created your first level!
Hope this helped, feel free to leave an upvote! :p

Related

ScintillaNet - detect mouse over

is it possible to react when the mouse is over a word ? Suppose I want to show a bubble with a description of the thing I'm currently hovering. Seems strangely difficult to do.
I think it is possible but might be a little hard.
You have the MouseHover event however you don't know what word you hovered so it might be a little hard.
You can get the mouse localization with this:
Point mouseLocation = new Point(e.X, e.Y)
Then if you use a fixed-width type font you know the size of each line/character then you can calculate it.
Some code that helps with position/line transition:
var line = scintilla.LineFromPosition(startPos);
startPos = scintilla.Lines[line].Position;
scintilla -> Control Name
For a better view try seeing this:
https://github.com/jacobslusser/ScintillaNET/wiki/Custom-Syntax-Highlighting
https://github.com/jacobslusser/ScintillaNET/wiki/Basic-Text-Retrieval-and-Modification
Edit:
Not really a good answer soo 2nd try
[scintilla name].CurrentPosition -> you can get the word you selected if I'm not mistaken but I don't know if you can do it by hovering.
Then do the interpretation of the word and it might work.
Try reading this:
https://github.com/jacobslusser/ScintillaNET/issues/149
3rt Try.
Let's hope it's the best one.
https://github.com/Ahmad45123/AutoCompleteMenu-ScintillaNET
There is AutoCompleteMenu for Scintilla that has a hover property.
I'm not sure how it works but might be what you're searching for.

Can AndroidDeveloper do anything like XCode's // MARK: - ...?

One of the features I use a bunch in larger code bodies in XCode is the ability to delineate/label blocks of functionality with // MARK: comments. These get used by the IDE to label things in the menus. I'm porting an app to AndroidStudio/Kotlin, and really missing this. Is there anything like this? I've found the Structure view, but I don't see any hints that comments influence it at all.
Not exactly the same but you can do:
//region RegionName
... code ...
//endregion
and you'll be able to fold this section of code.

Swift - Get CCNode from scene

I've tried to search on the internet for a method that can get a specific node from the scene. I've seen a lot of methods, but it doesn't give me a clear answer.
I've have build a scene in SpriteBuilder from Cocos2D. This is how the MainScene.ccb looks like:
If needed: This is how Player.ccb looks like:
I'm trying to get the player 'object' in Xcode after I published the project. I've tried to use CCBReader, but I can't find any useful method (unless I missed it). Also I've tried so use self.children, but I don't know how to continue any further with that.
Can you help me out? At the end, I want to get the position of the player.
Thanks!
By the way, I'm a beginner in Swift, so don't expect that I know all of the terms.
When you add nodes (sprite) to your sprite builder project, make sure it is selected, then on the right, click theorem code connections tab. In the 'Doc root var' type your variable name in the box.
When you load Xcode select the file that loads the scene from sprite builder and you can then declare a variable in this file with the same name you gave it in sprite builder. You will then be able to use that node (sprite) whenever you want and access it's properties.

How to Fix Error: Incompatible Pointer Types Assigning to

Let me preface this by saying I'm new so I might not be the best at asking questions but here it goes. I am getting this error when I hit build in XCode with this code.
-(IBAction)unwindToRecipeDetails:(UIStoryboardSegue*)segue
{
ChangeRecipeDetailViewController *source = [segue sourceViewController];
recipeLabel = source.textView; // error: Incompatible Pointer Types Assigning to UILabel from UITextField
}
Here's what I'm trying to do. I based the code off of this snippet which works...
-(IBAction)unwindToRecipeBook:(UIStoryboardSegue *)segue;
{
AddRecipeViewController *source = [segue sourceViewController];
RecipeItem *item = source.recipeItem;
}
This is supposed to make AddRecipeViewController the data source for the initial RecipeBook page when the user navigates backward. I'm trying to implement the same thing for when a user navigates backward from the ChangeRecipe page to the RecipeDetails page.
Apparently I mixed two different types of code in the error, UILabel and UITextField. I get that they are incompatible but what could I change either one to in order to make it work. It is a little different than what I am basing my code off of in that I don't just want to transfer the same text, I want to change its format as well.
Again, I'm new at this so if anyone needs more information I'll gladly post it. Thanks.
Update 1: Palpatim: Thank you. Your solution worked. So to clarify, in order to transfer text I have to put .text after the initial source. This combines two unlike objects and transfers only text to text. Is this correct? I'm new at coding and am just trying to learn.
Philip Mills: I meant I wanted to change the format of the text when I transfer it from something that is editable like a textview to something static like a label.
Thanks for the help.

BoxLayout in Cocoa

Originally, I wanted to ask how to create user interfaces with cocoa programmatically, i.e. without using interface builder. But it seems that someone else has already asked this question and the answers didn't help me.
So I'll ask a different question, that I hope will indirectly help me answer the previous question. Here it is:
(QUESTION_START)
How do I create an Objective C class that is equivalent in functionality with the BoxLayout class in Java? (Just click the link, the image on that page says everything you need to know about BoxLayout.)
(QUESTION_END)
Any help in the right direction will be appreciated!
There are a few sub tasks that are connected with the question, e.g.
"How do I ask a user interface element (e.g. a button) how large it wants to be" (before it has been drawn to the screen). To draw it on the screen you have to already know its size, don't you? Obviously, the interface builder application has figured out a way to do this.
I know that many Cocoa developers think it's a stupid idea to even try what I want to do. Let me tell you: I know the reasoning behind that opinion. Right now, laying out controls without interface builder sucks, because there is nothing that comes even close to a layout manager in cocoa. But if you think my question is stupid, please DONT answer. The whole internet is full of explanations why you would never want to create UIs with code in cocoa.
Thanks!
Answering your first question is kind of difficult and fairly involved, so I'm going to dive into your subquestion first:
How do I ask a user interface element (e.g. a button) how large it wants to be?
When you create a UI element, you tell it how big it should be (as well as where it should be) via its initWithFrame: constructor; or you can set its frame later via its setFrame: method. It will then draw itself into that space. You can get an element's frame via its frame method.
With that in mind, a BoxLayout class would, hypothetically, be a controller of some sort in which you could add UI elements, and then the BoxLayout controller would arrange them in a grid (or whatever) on an NSView of some sort.
I know you weren't looking for answers that questions motives, but given the complexity of a BoxLayout class vs. laying out the interface in IB, it seems relevant to ask why you want to do this.

Resources