I have a problem setting up the camera in my swift 3 project.
and this is my code
cameraNode = childNode(withName: "cameraNode") as! SKCameraNode
view.scene?.camera = cameraNode
Can you help me figure out whats wrong here? Even if i move the camera in my scene editor, it won't make any difference in the view of my game.
Thanks a lot!
Alright mate, got you fam don't worry.
Set a variable the looks something like this,
var GameSceneCamera = SKCameraNode()
Keep your first line of code specifically this,
cameraNode = childNode(withName: "cameraNode") as! SKCameraNode
And delete your second line of code specifically this,
view.scene?.camera = cameraNode
Right, last step mate, this is very important so listen very carefully,
Go to the file GameScene.sks
Open the navigation side bar or Navigator (click on the third button from the top right) to open up your assets on the side
Click on, Scene, or the top asset that contains all of these assets
open the side bar on the right or Utilities (click on the first button from the top right)
Click on camera and select the node
If you can't figure this out you are a special type of stupid lol.
Related
So I am very new to unity. and I used this tutorial to create a shooting mechanic for my prototype. moving right and shooting projectiles works fine but when I move left the projectiles are not visible in the game view . I noticed they are in the scene when I run the game. I believe this has nothing to do with my code. since when I press the button it shoots and destroys. it's just not visible when I am moving left. is this a visual issue??
I have screenshots here to provide a better example. of what I'm experiencing. and the links to the movement and projectile code as well for any references. if anyone knows an easy fix it would be much appreciated. If you need to see my code i will include a follow up.
Movement:https://www.youtube.com/watch?v=n4N9VEA2GFo&t=20s[enter image description here]1
Projectile:https://www.youtube.com/watch?v=8TqY6p-PRcs&t=264s
#Nyssa Wootton Welcome to StackOverflow.Try the bullet spawning approach you no need to attach a bullet with the player. Just assign a bullet in inspector and it will spawn a bullet whenever the user clicks on the button. have a look at this code
public GameObject bulletPrefab;
public Transform spawnPos;
public float bulletSpeed = 100f;
void Update () {
if (Input.GetMouseButtonDown(0)){ // on fire btn press
var bullet = Instantiate(bulletPrefab , spawnPos , Quaternion.identity);
// make sure you're prefab have rigidbody on it
bullet.GetComponent<Rigidbody>().AddForce(transform.forward * bulletSpeed , ForceMode.Impulse);
Destory(bullet , 2); // destorys after 2 second
}
}
I am having a weird problem with xcode, I created a button with an image in it, and trying to put center the image in the button.
It is weird that if I click center horizontal in xcode, it always one step close to the left side. If I set it align with the right side, it isnt going to the right end. Anyone have any cue what is wrong with my xcode...
thanks for helping me out, please see the screenshot for your information.
1
In size inspector, check a Content insets and Image insets right and left if are set to zero
I'm trying to update my app for the new iPhone X. After reading about the safe area feature and the check box "Safe Area Relative Margins" in each UIObject's "Size Inspector" (ruler tab), I didn't think this would be too bad. However, that feature does not seem to be working for me.
Nothing changed for regular iPhones, which is good, however for the X, the top of my app overlaps the top inset of the phone by a third. Is there any known way to fix this* or something I'm missing?
*By fix this, I mean make it so that my objects start below the outcrop, like the second picture.
What is happening:
Desired Behavior (from https://arstechnica.com/gadgets/2017/11/how-devs-updated-their-apps-for-the-iphone-xs-screen-and-the-notch/):
I too have wasted hours on this. And while I cannot answer your question of why this is broken in Xcode, I can provide a solution.
But first let me note than in Xcode 11.3.1, I experience the same issue in a new project created from scratch.
Set up your storyboard:
On your storyboard, select "Use Safe Area Layout Guides". This will add a safe area to each of your ViewControllers. It will also require you to target iOS9+. You might be able to skip this step though (see step 4 below).
View your storyboard as iPhone 4s.
Fix each ViewController:
Select all views under the top-level view.
Click Editor | Embed In | View Without Inset. This creates a new view and puts all your views inside.
Make this new view expand to the safe area by adding safe area constraints (by control-dragging your new view onto the top level view).
Leading space to safe area
Top space to safe area
Trailing space to safe area
Bottom space to safe area
If you did not opt into using a safe area storyboard above, you may be able to create four equivalent constraints by using the Top Layout Guide, Bottom Layout Guide, and the left/right sides of the top-level view. This may not work in landscape though. And I did not test this.
Set your new view as transparent.
Give your new view a name like "SafeAreaView".
In iOS 11, margins are inset from the safe area. Thus, your zero top margin becomes a 20 top margin — explaining your screen shot. If that's not what you want, set the view's insetsLayoutMarginsFromSafeArea property to false.
In my case modalPresentationStyle = .fullScreen has to be set to the view controller being presented
I've just started learning Swift and Xcode, so I apologise in advance if my question is confusing or missing information. Please let me know if that's the case.
My question is on the automatic navigation bar created when I embed my scenes in the navigation controller.
As I've tried to show in my screenshot in the link below, my idea is to use the "Refusion" button in scene 1 to show scene 2. This works. However, scene 2 does not generate an automatic back button this way, which is what I'm trying to get.
If I create a button in scene 2 that shows scene 1 upon being pressed, scene 1 will now have an automatically generated back button. But this sends the user/me back from scene 1 to scene 2.. Which I already have my "Refusion" button for and also it just creates a confusing loop.
So, my question is: I'm trying to figure out how to get the auto-back button on my scene 2 and just scene 2, how do I do that? I'm probably doing something wrong, but would appreciate any help in where my error is.
I've embedded both scenes in the navigation controller.
Thanks,
https://ibb.co/jfZeSa
You need to embed only scene 1 in navigation controller.
When you tap on Refusion button, push scene 2. Scene 2 then will be added in the navigation stack. In this case default back button will appear on the navigation bar.
In case you present scene 2 from scene 1, back button won't appear on the navigation bar. i.e. scene 2 won't be added in the navigation stack.
Back button on navigation bar only appear on the controllers that are the part of navigation stack.
Okay, so I have this button in my project and it is very important to the entirety of the code. Anyway, during the placing and constraining process, I somehow moved this button to the very top of the view controller just above the status bar. When I try to click on it and move it, I instead select the view controller. I have looked everywhere for a solution but it seems no one is having this same issue. Any suggestions? Thanks in advance!
Click on the button item in the list on the left, and then in the Size Inspector (next to the attributes inpector) change the height to some insanely big number. You will then be able to move it down.