- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
I have made it so that when you tap on the left or right side of the screen it will move accordingly by moving the worldNode
import SpriteKit
import UIKit
import GameplayKit
var ground = Ground(imageNamed: "grass.png")
var sceneBody = SKPhysicsBody()
enum BodyType:UInt32 {
case Player = 1
case Wall = 2
case Ground = 4
case AnotherObject = 8
case AnotherObject2 = 16
case AnotherObject3 = 32
case AnotherObject4 = 64
}
class GameScene: SKScene, SKPhysicsContactDelegate{
var player = Player(imageNamed: "p1_walk02.png")
let theCamera: SKCameraNode = SKCameraNode()
var textAtlas = SKTextureAtlas()
var textArry = [SKTexture]()
var worldNode = SKNode()
override func didMoveToView(view: SKView) {
self.physicsWorld.gravity = CGVectorMake(0, -9.8)
physicsWorld.contactDelegate = self
self.anchorPoint = CGPointMake(0, 0)
self.backgroundColor = SKColor.whiteColor()
//self.camera?.position = player.position
addChild(worldNode)
let spawn = SKAction.runBlock({
() in
self.makeGU1()
})
let delay = SKAction.waitForDuration(2)
let seq = SKAction.sequence([spawn, delay])
worldNode.runAction(SKAction.repeatAction(seq, count: 1))
self.addChild(player)
player.xScale = 0.5
player.yScale = 0.5
player.position = CGPoint(x: self.frame.width*0.3, y: ground.position.y+56)
worldNode.position = self.position
worldNode.xScale = self.xScale
worldNode.yScale = self.yScale
}
func scheduledTimerWithTimeInterval(){
//Scheduling timer to Call the function **Countdown** with the interval of 1 seconds
let myTimer = NSTimer.scheduledTimerWithTimeInterval(0.5, target: self, selector: Selector("updateCounting"), userInfo: nil, repeats: true)
}
func updateCounting() {
}
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
for touch in touches {
let location = touch.locationInNode(self)
print(location)
//-7.49999237060547
if player.position.x > 230.499969482422{
}
if location.x > self.frame.width/2 {
// Left side of the screen
textAtlas = SKTextureAtlas(named: "Walk")
for i in 1...textAtlas.textureNames.count{
let Name = "p1_walk0\(i).png"
textArry.append(SKTexture(imageNamed: Name))
}
let Animate = SKAction.animateWithTextures(textArry, timePerFrame: 0.1)
player.runAction(SKAction.repeatActionForever(Animate), withKey: "Left run")
print(location)
worldNode.runAction(SKAction.repeatActionForever(SKAction.moveBy(CGVectorMake(1000, 0), duration: 4).reversedAction()), withKey: "moveLeft")
self.runAction(SKAction.repeatActionForever(SKAction.moveBy(CGVectorMake(1000, 0), duration: 4).reversedAction()), withKey: "moveLeft")
} else {
textAtlas = SKTextureAtlas(named: "Walk")
for i in 1...textAtlas.textureNames.count{
let Name = "p1_walk0\(i).png"
textArry.append(SKTexture(imageNamed: Name))
}
let Animate = SKAction.animateWithTextures(textArry, timePerFrame: 0.1)
player.runAction(SKAction.repeatActionForever(Animate), withKey: "Left run")
print(location)
worldNode.runAction(SKAction.repeatActionForever(SKAction.moveBy(CGVectorMake(1000, 0), duration: 4)), withKey: "moveLeft")
self.runAction(SKAction.repeatActionForever(SKAction.moveBy(CGVectorMake(1000, 0), duration: 4)), withKey: "moveLeft")
}
}
}
override func touchesEnded(touches: Set<UITouch>, withEvent event: UIEvent?) {
player.removeActionForKey("Left run")
var tex = [SKTexture]()
tex.append(SKTexture(imageNamed:"p1_walk02.png"))
player.runAction(SKAction.animateWithTextures(tex, timePerFrame: 0.2))
worldNode.removeActionForKey("moveLeft")
self.removeActionForKey("moveLeft")
}
func makeGU1(){
This is where I set up the scene
var ground1 = SKSpriteNode(imageNamed: "grass.png")
var ground2 = SKSpriteNode(imageNamed: "grass.png")
var ground0 = SKSpriteNode(imageNamed: "grass.png")
var ground3 = SKSpriteNode(imageNamed: "grass.png")
var ground4 = SKSpriteNode(imageNamed: "grass.png")
var ground5 = SKSpriteNode(imageNamed: "grass.png")
var ground6 = SKSpriteNode(imageNamed: "grass.png")
var ground7 = SKSpriteNode(imageNamed: "grass.png")
var ground8 = SKSpriteNode(imageNamed: "grass.png")
var ground9 = SKSpriteNode(imageNamed: "grass.png")
var ground10 = SKSpriteNode(imageNamed: "grass.png")
var ground11 = SKSpriteNode(imageNamed: "grass.png")
var ground12 = SKSpriteNode(imageNamed: "grass.png")
var ground13 = SKSpriteNode(imageNamed: "grass.png")
ground0.xScale = 0.7
ground0.yScale = 0.7
ground0.position = CGPoint(x: 20, y: 10)
worldNode.addChild(ground0)
ground0.physicsBody = SKPhysicsBody(rectangleOfSize: ground0.size)
ground0.physicsBody?.affectedByGravity = false
ground0.physicsBody?.dynamic = false
ground0.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground0.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground0.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground0.copy()
ground1 = ground0.copy() as! SKSpriteNode
ground1.position = CGPoint(x: ground0.position.x+ground1.size.width, y: 10)
ground1.copy()
worldNode.addChild(ground1)
ground2.xScale = 0.7
ground2.yScale = 0.7
ground2.physicsBody = SKPhysicsBody(rectangleOfSize: ground2.size)
ground2.physicsBody?.affectedByGravity = false
ground2.physicsBody?.dynamic = false
ground2.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground2.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground2.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground2.position = CGPoint(x: ground1.position.x+ground2.size.width, y: 10)
worldNode.addChild(ground2)
ground3.xScale = 0.7
ground3.yScale = 0.7
ground3.physicsBody = SKPhysicsBody(rectangleOfSize: ground3.size)
ground3.physicsBody?.affectedByGravity = false
ground3.physicsBody?.dynamic = false
ground3.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground3.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground3.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground3.position = CGPoint(x: ground2.position.x+ground3.size.width, y: 10)
worldNode.addChild(ground3)
ground4.xScale = 0.7
ground4.yScale = 0.7
ground4.physicsBody = SKPhysicsBody(rectangleOfSize: ground4.size)
ground4.physicsBody?.affectedByGravity = false
ground4.physicsBody?.dynamic = false
ground4.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground4.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground4.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground4.physicsBody?.affectedByGravity = false
ground4.physicsBody?.dynamic = false
ground4.position = CGPoint(x: ground3.position.x+ground4.size.width, y: 10)
worldNode.addChild(ground4)
ground5.xScale = 0.7
ground5.yScale = 0.7
ground5.physicsBody = SKPhysicsBody(rectangleOfSize: ground5.size)
ground5.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground5.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground5.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground5.physicsBody?.affectedByGravity = false
ground5.physicsBody?.dynamic = false
ground5.position = CGPoint(x: ground4.position.x+ground5.size.width, y: 10)
worldNode.addChild(ground5)
ground6.xScale = 0.7
ground6.yScale = 0.7
ground6.physicsBody = SKPhysicsBody(rectangleOfSize: ground6.size)
ground6.physicsBody?.affectedByGravity = false
ground6.physicsBody?.dynamic = false
ground6.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground6.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground6.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground6.position = CGPoint(x: ground5.position.x+ground6.size.width, y: 10)
worldNode.addChild(ground6)
ground7.xScale = 0.7
ground7.yScale = 0.7
ground7.physicsBody = SKPhysicsBody(rectangleOfSize: ground6.size)
ground6.physicsBody?.affectedByGravity = false
ground7.physicsBody?.dynamic = false
ground7.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground7.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground7.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground7.position = CGPoint(x: ground6.position.x+ground7.size.width, y: 10)
worldNode.addChild(ground7)
ground8.xScale = 0.7
ground8.yScale = 0.7
ground8.physicsBody = SKPhysicsBody(rectangleOfSize: ground8.size)
ground8.physicsBody?.affectedByGravity = false
ground8.physicsBody?.dynamic = false
ground8.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground8.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground8.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground8.position = CGPoint(x: ground7.position.x+ground8.size.width, y: 10)
worldNode.addChild(ground8)
ground9.xScale = 0.7
ground9.yScale = 0.7
ground9.physicsBody = SKPhysicsBody(rectangleOfSize: ground9.size)
ground9.physicsBody?.affectedByGravity = false
ground9.physicsBody?.dynamic = false
ground9.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground9.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground9.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground9.position = CGPoint(x: ground8.position.x+ground9.size.width, y: 10)
worldNode.addChild(ground9)
ground10.xScale = 0.7
ground10.yScale = 0.7
ground10.physicsBody = SKPhysicsBody(rectangleOfSize: ground10.size)
ground10.physicsBody?.affectedByGravity = false
ground10.physicsBody?.dynamic = false
ground10.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground10.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground10.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground10.position = CGPoint(x: ground9.position.x+ground10.size.width, y: 10)
worldNode.addChild(ground10)
ground11.xScale = 0.7
ground11.yScale = 0.7
ground11.physicsBody = SKPhysicsBody(rectangleOfSize: ground11.size)
ground11.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground11.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground11.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground11.physicsBody?.affectedByGravity = false
ground11.physicsBody?.dynamic = false
ground11.position = CGPoint(x: ground10.position.x+ground11.size.width, y: 10)
worldNode.addChild(ground11)
ground12.xScale = 0.7
ground12.yScale = 0.7
ground12.physicsBody = SKPhysicsBody(rectangleOfSize: ground12.size)
ground12.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground12.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground12.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground12.physicsBody?.affectedByGravity = false
ground12.physicsBody?.dynamic = false
ground12.position = CGPoint(x: ground11.position.x+ground12.size.width, y: 10)
worldNode.addChild(ground12)
//if ground13.parent == nil {
ground13.xScale = 0.7
ground13.yScale = 0.7
ground13.physicsBody = SKPhysicsBody(rectangleOfSize: ground13.size)
ground13.physicsBody?.categoryBitMask = BodyType.Ground.rawValue
ground13.physicsBody?.collisionBitMask = BodyType.Player.rawValue
ground13.physicsBody?.contactTestBitMask = BodyType.Player.rawValue
ground13.physicsBody?.affectedByGravity = false
ground13.physicsBody?.dynamic = false
ground13.position = CGPoint(x: ground12.position.x+ground13.size.width, y: 10)
worldNode.addChild(ground13)
//}
}//end of Make Block
}
This makes just enough to fill the ground of the screen of a iphone 6
最佳答案
我有code on github创建无限滚动的背景。它与制作视差背景有关,但您可以在其中看到让它无限滚动的代码。诀窍是创建足够的地面节点来覆盖宽度,并为每一端添加一些额外的节点。当左边的完全移出屏幕时(通过检查它的 origin.x + size.width
值与 View 的原点),您将其拾起并将其移动到最右侧。相反,如果您向另一个方向移动,并发现最后一个节点完全超出屏幕,则可以拾取最右边的节点并将其移动到开头。
如果做得正确,它看起来很流畅而且相当简单。
关于ios - 我正在尝试制作一款横向卷轴游戏,但我正在努力无限地生成地面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36120511/
即使我的设备旋转(纵向->横向->纵向),我也需要始终以横向模式录制视频。 取角度很简单,我用的是hyroscope。我的问题是总是横向录制视频。需要任何建议。 我正在使用 AVCaptureSess
我正在 iPad(1,2) 以及 Samsung Tab 2 上测试我的网络应用程序。我有不同的 CSS(外部)集可应用于 iPad 上的横向/纵向模式和选项卡 2 上的横向/纵向模式。 但我无法为
我正在将Snappy Bundle和Symfony 2.1一起使用。 我有一些问题未在此捆绑包的文档中找到: 如何设置方向? 有没有显示页码的方法? 这是我的捆绑包的config.yml: knp_s
我一直在寻找这个问题的答案,但找不到任何答案。显然,iPhone SDK 3.0 使得 UIImagePickerController 可以以横向模式显示成为可能 - 但我没有找到任何允许这样做的方法
我有 1 个 Storyboard,我在 Swift 3 中的 Xcode 8 上使用带有大小类的自动布局。 我有这个当前的肖像 View : 目前,这是 1 个带有标签的垂直堆栈 View 。 在横
我正为这个而焦头烂额。基本上,我需要我的菜单根据菜单的内容水平放置一个容器。所以,我知道 table 和 table-cell 属性可以做到这一点。但是,当我将其与 Superfish Menu 结合
我努力做到这一点: 但我无法正确获取第三列和翻转的标题。 我现在是这样的: 最佳答案 该解决方案适用于 IE9、Chrome、Firefox、Safari 和 Opera,不需要 JavaScrip
我想要一个水平方向的 WPF DataGrid,有人知道解决方案吗? 最佳答案 我之前已经这样做了,因为我们希望能够对 DataGrid 和 PropertyGrid 使用相同的控件。很多事情都必须改
我正在开发一个适用于智能手机的网站版本,在处理智能手机横向方向的媒体查询时遇到了一个小问题。对于纵向,我正在使用以下媒体查询并且它工作得很好: @media only screen and (max-
如何让“AVCaptureVideoPreviewLayer”在横向方向上正确显示?它在纵向模式下工作正常但不旋转,并且当父 View Controller 处于横向模式时显示旋转的相机捕获。 最佳答
这个问题在这里已经有了答案: Force "portrait" orientation mode (12 个回答) 关闭2年前。 我的第一款 Android 游戏即将完成,但我遇到了一个非常简单的问题
我的数据在其中一个字段中具有嵌套映射。例如,数据位于名为“customers”的表中,如下所示: 姓名:比尔·琼斯 地址:{"billing":{"street":"123 Main", "city"
我正在横向模式下运行应用程序。我需要注意什么才能使拍摄的屏幕截图也处于横向模式。 我在 iPhone 应用程序中使用以下代码,底部有标签栏并拍摄屏幕截图,但它始终仅处于纵向模式。为什么? UIWind
谁能举例说明如何将单点触控应用程序的 View 从纵向旋转为横向,反之亦然? 最佳答案 如果您在 Interface Builder 中设置 ui 元素的几何形状,请确保在 Size Inspecto
我正在使用简单的 MPMoviePlayerController。在纵向模式下,它嵌入到我的布局中。当我旋转我的设备时,我希望它全屏显示。在全屏模式下,有一个完成按钮,但它唯一的作用就是暂停视频。当点
我正在尝试读取 JSON 模式,但似乎无法弄清楚如何将所有先前对象等输出到层次结构中。 这是JSON响应方案 { "Shopping": { "Orders": { "OrderInfo": {
我想在我的布局中包含一个 SlidingDrawer,但我会将它放在布局的侧面。所以开口是从左到右,而不是从下往上。这怎么办? 最佳答案 this link可能会帮助您创建水平滑动抽屉。如果您正在使用
就在我以为我已经解决了所有问题时..我遇到了这个问题。 场景。 我有一个简单的 tableView。并在导航项的 titleView 中带有搜索栏。 SearchBar 通过 View Control
我有一个带有 MGSplitView 的应用程序,其中包含表格 View 和 UIWebView,该应用程序固定为横向。 Web View 有一个附加到 Web View 的 UITapGesture
我有一部 iPhone,我正在添加横向支持。之前只是肖像。 当键盘显示时,我无法将文本字段移开。 我使用的解决方案与记录在案的 Apple 解决方案非常相似 here . 该解决方案在纵向模式下工作正
我是一名优秀的程序员,十分优秀!