Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
198 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ platforms/ | |
# NativeScript Template | ||
*.js.map | ||
*.js | ||
!notes/*.js | ||
!webpack.config.js | ||
*.css | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// SKScene is SpriteKit; SCN is SceneKit | ||
// https://stackoverflow.com/questions/26225236/swift-spritekit-adding-button-programmatically | ||
const ButtonTestScene = SKScene.extend( | ||
{ | ||
initWithFrame(frame){ | ||
SKScene.prototype.init.apply(this, []); | ||
// this.frame = frame; /* readonly */ | ||
// this.frame.size = frame.size; | ||
// this.frame.size.x = frame.size.x; | ||
// this.frame.size.y = frame.size.y; | ||
this.frame.origin = frame.origin; | ||
return this; | ||
}, | ||
didMoveToView: function (view){ | ||
this.button = SKSpriteNode.alloc().initWithColorSize( | ||
UIColor.alloc().initWithRedGreenBlueAlpha(1,0,0,1), | ||
CGSizeMake(100, 44) | ||
); | ||
|
||
this.button.position = CGPointMake( | ||
CGRectGetMidX(this.frame), | ||
CGRectGetMidY(this.frame), | ||
); | ||
|
||
this.addChild(this.button); | ||
}, | ||
|
||
// touchesEndedWithEvent(touches: NSSet<UITouch>, event: _UIEvent): void; | ||
touchesEndedWithEvent: function (touches, event){ | ||
// Synchronous | ||
touches.enumerateObjectsUsingBlock((touch, i) => { | ||
const location = touch.locationInNode(this); | ||
if(button.containsPoint(location)){ | ||
// Respond to tap somehow. | ||
} | ||
}); | ||
} | ||
}, | ||
{ | ||
name: "ButtonTestScene", | ||
protocols: [], | ||
exposedMethods: { | ||
"initWithFrame": { | ||
params: [CGRect], | ||
returns: SKScene | ||
} | ||
} | ||
} | ||
); | ||
|
||
ButtonTestScene.alloc().initWithFrame(CGRectMake(2, 2, 25, 25)); | ||
|
||
|
||
const GameViewController = UIViewController.extend( | ||
{ | ||
viewDidLoad: function(){ | ||
UIViewController.prototype.viewDidLoad.apply(this, arguments); | ||
|
||
this.view = SKView.alloc().initWithFrame(this.view.bounds); | ||
if(this.view instanceof SKView){ | ||
const scene = | ||
} | ||
} | ||
}, | ||
{ | ||
name: "GameViewController", | ||
protocols: [] | ||
} | ||
); | ||
|
||
new GameViewController(); | ||
|
||
|
||
// https://stackoverflow.com/questions/53104428/spritekit-example-without-storyboard | ||
/* | ||
class GameViewController: UIViewController { | ||
|
||
// MARK: View Controller overrides | ||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
view = SKView(frame: view.bounds) | ||
|
||
if let view = self.view as! SKView? { | ||
// Initialise the scene | ||
let scene = GameScene(size: view.bounds.size) // <-- IMPORTANT: Initialise your first scene (as you have no .sks) | ||
|
||
// Set the scale mode to scale to fit the window | ||
scene.scaleMode = .aspectFill | ||
|
||
// Present the scene | ||
view.presentScene(scene) | ||
|
||
// Scene properties | ||
view.showsPhysics = false | ||
view.ignoresSiblingOrder = true | ||
view.showsFPS = true | ||
view.showsNodeCount = true | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
// eachChild = ScrollView, which is a View | ||
// eachChildView = TextView, which is a ViewBase | ||
function printView(view, tabDepth) { | ||
if(typeof tabDepth === "undefined") tabDepth = 0; | ||
let buffer = ""; | ||
|
||
// buffer += "[" + (typeof view.eachChildView !== "undefined") + "]"; | ||
|
||
view.eachChild((child) => { | ||
// view.eachChild((child) => { | ||
const opener = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName; | ||
buffer += opener; | ||
|
||
// buffer += "[" + (typeof child.eachChildView !== "undefined") + "]"; | ||
|
||
let children = 0; | ||
child.eachChild((subchild) => { | ||
if(children === 0) buffer += ">\n"; | ||
children++; | ||
// isView check | ||
// buffer += "[" + (typeof subchild.eachChildView !== "undefined") + "]"; | ||
buffer += printView(subchild, tabDepth + 1); | ||
return true; | ||
}); | ||
|
||
if(children === 0){ | ||
if(child.eachChildView){ | ||
child.eachChildView((subchild) => { | ||
if(children === 0) buffer += ">\n"; | ||
children++; | ||
buffer += printView(subchild, tabDepth + 2); | ||
return true; | ||
}); | ||
} | ||
} | ||
|
||
if(children === 0){ | ||
buffer += "/>\n"; | ||
} else { | ||
const closer = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName + "/>"; | ||
buffer += closer + '\n'; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
// if(view.eachChildView){ | ||
// buffer += "[ECV]"; | ||
// } else { | ||
// buffer += "[EC]"; | ||
// } | ||
|
||
if(view.eachChildView) view.eachChildView((child) => { | ||
// view.eachChild((child) => { | ||
const opener = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName; | ||
buffer += opener; | ||
|
||
// buffer += "[" + (typeof child.eachChildView !== "undefined") + "]"; | ||
|
||
let children = 0; | ||
child.eachChild((subchild) => { | ||
if(children === 0) buffer += ">\n"; | ||
children++; | ||
// isView check | ||
// buffer += "[" + (typeof subchild.eachChildView !== "undefined") + "]"; | ||
buffer += printView(subchild, tabDepth + 1); | ||
return true; | ||
}); | ||
|
||
if(children === 0){ | ||
if(child.eachChildView){ | ||
child.eachChildView((subchild) => { | ||
if(children === 0) buffer += ">\n"; | ||
children++; | ||
buffer += printView(subchild, tabDepth + 2); | ||
return true; | ||
}); | ||
} | ||
} | ||
|
||
if(children === 0){ | ||
buffer += "/>\n"; | ||
} else { | ||
const closer = new Array(tabDepth).fill(" ").join('') + "<" + child.typeName + "/>"; | ||
buffer += closer + '\n'; | ||
} | ||
|
||
return true; | ||
}); | ||
|
||
if(tabDepth === 0) console.log(buffer); | ||
return buffer; | ||
} | ||
global.printView = printView; | ||
printView(app.getRootView()); |