SKLightNode causes crash if added too soon with SKSpriteNode - ios

I have a scene with 20ish SKSpriteNodes that are added at run time. I also Add an SKLightNode
However I get a crash with the following log
-[MTLDebugRenderCommandEncoder validateDrawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:function:]:5605: failed assertion `Draw Indexed Primitives Validation indexBufferOffset(12) + (indexCount(222) * 2) must be <= [indexBuffer length](240). ' -[MTLDebugRenderCommandEncoder validateDrawIndexedPrimitives:indexCount:indexType:indexBuffer:indexBufferOffset:instanceCount:function:]:5605: failed assertion `Draw Indexed Primitives Validation indexBufferOffset(12) + (indexCount(222) * 2) must be <= [indexBuffer length](240).
If I wait 10 seconds to add the SKLightNode the crash doesnt happen, also if I disable shadows on the SKSpriteNode the crash doesnt happen.
Fyi this was an old swift 2 project that worked fine, I manually upgraded it to swift 4 and these issues started, any ideas?
the SKLightNode SKSpriteNodes are as follows
let light = SKLightNode();
light.categoryBitMask = 1;
light.falloff = 1;
light.ambientColor = .white
light.lightColor = .white
light.shadowColor = .black
let tree1 = SKSpriteNode(texture: SKTexture(imageNamed: "tree1.png"), color: grayColor, size: CGSize(width: 120, height: 270));
tree1.color = grayColor;
tree1.colorBlendFactor = 1;
tree1.position = CGPoint(x: (self.frame.size.width/2) - 170, y: 730)
tree1.shadowCastBitMask = 1;
tree1.shadowedBitMask = 1;
tree1.name = String(format: "%f", tree1.position.y)

Related

Kivy: ScrollView squishes together the layout

I am new to Kivy and this is my first time trying to create a scrollView.
I am trying to do a 'Splitwise' ripoff where you can create expenses and let the app figure out who should pay who etc.
I am trying to create a method that opens a popup with all members and their balances as well as a button with the text 'Settle up'. Underneath the balances should be a list of all the registered debts, and you should be able to scroll down to see them all. The popup should also contain a 'Cancel'-button.
My problem is that my code doesn't enable scrolling, and also squishes together the content in the pop up. See picture.
All help highly appreciated!
See (messy) code below:
sbl_ret = GridLayout(cols = 1)
sbl_balances = GridLayout(cols = 3)
sbl_balances.add_widget(Label())
sbl_balances.add_widget(Label(text = 'Balances', font_size = '20sp', size_hint = (1,.2), color = backgroundColor, bold = True))
sbl_balances.add_widget(Label())
for member in self.members:
sbl_balances.add_widget(Label(text = member.getName(), font_size = 40, size_hint_y = None, height = 60))
sbl_balances.add_widget(Label(text = str(round(member.getBalance())) + ' kr', font_size = 40, size_hint_y = None, height = 60))
sbl2 = BoxLayout(orientation = 'vertical')
sbl2.add_widget(Label(size_hint = (1,.2)))
btn = Button(text = 'Settle up', background_color = buttonColor, bold = True, size_hint_y = None, height = 60)
btn.bind(on_press = lambda member: self.settleUp())
sbl2.add_widget(btn)
sbl2.add_widget(Label(size_hint = (1,.2)))
sbl_balances.add_widget(sbl2)
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(text = 'Debts', font_size = '20sp', color = backgroundColor, bold = True))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
for member in self.members:
for debt in member.getDebtList():
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.add_widget(Label(size_hint_y = None, height = 60, text = debt.getToWhom().getName() + ' lent ' + str(debt.getAmount()) + ' SEK to ' + debt.getFromWhom().getName() + ' for ' + debt.getDescription(), font_size = 40))
sbl_balances.add_widget(Label(size_hint = (.2,1)))
sbl_balances.bind(minimum_height=sbl_balances.setter('height'))
sbl3 = BoxLayout(size_hint = (1,.15))
sbl3.add_widget(Label(size_hint = (.2,1)))
b = Button(text = 'Cancel', background_color = entryColor, size_hint_y = None, height = 150)
b.bind(on_press = lambda x: self.balanceDialog.dismiss())
sbl3.add_widget(b)
sbl3.add_widget(Label(size_hint = (.2,1)))
sv = ScrollView(do_scroll_x = False)
sv.add_widget(sbl_balances)
sbl_ret.add_widget(sv)
sbl_ret.add_widget(sbl3)
self.balanceDialog = Popup(title = 'Group view', content = sbl_ret, title_align = 'center',
title_color = backgroundColor, background_color = [0,0,0,.7], separator_height = 0, title_size = '28sp')
self.balanceDialog.open()
'''
Try adding size_hint_y=None to your code creating the GridLayout:
sbl_balances = GridLayout(cols = 3, size_hint_y=None)
See the documentation.

iOS Progress bar custom maximum and minimum values

I have Label in my UIView which continuously changes values in between 80(min) to 475(Max) now I have run the progress bar status with respect to max and min value of label continuously. below where the code i have tried till now
if ampsMaxValue <= 80
{
ampsMaxValue = 80
ampsLabel.text = String(ampsMaxValue)
ampsprogressBar.progress = Float(0)
return
}
ampsMaxValue = ampsMaxValue - 1
ampsLabel.textColor = UIColor.white
ampsprogressBar.tintColor = UIColor.red
ampsLabel.text = String(ampsMaxValue)
v -= 0.1
ampsprogressBar.progress = Float(v)
}else{
if ampsMaxValue >= 475
{
ampsMaxValue = 475
ampsLabel.text = String(ampsMaxValue)
ampsprogressBar.progress = Float(1)
return;
}
ampsMaxValue = ampsMaxValue + 1
ampsLabel.textColor = UIColor.white
ampsprogressBar.tintColor = UIColor.red
ampsLabel.text = String(ampsMaxValue)
v += 0.1
ampsprogressBar.progress = Float(v)
}
I was able show the increased and decreased value by 0.1, but not solved it. need info about how calculate the exact increased and decreased value for the progress bar with respect to the label max an min value.
Try:
v = (ampsMaxValue - 80) / (475 - 80)

Swift game lags when creating spritenodes

So I have recently uploaded a game to the app store and have been users reporting lags on older devices.
First of all, the game:
It is called "CURVE" (I am not sure if I am allowed to post its name here, but it would help you understand the problem).The idea of the game is that a ball moves up the screen and passes in gaps between walls. Also there are smaller balls that fall down from the main one, thus creating some sort of path.
Now, the lags. They occur in two main moments. First, when the path is created and second, when the player gets through the gaps.
When the player passes through the gaps, he collides with an invisible node. The collsion is noted, the score is updated. The node is then removed and the player proceeds.
I believe the lags occur when swift either creates a SpriteNode or deletes one. Any ideas as to how to deal with this problem?
Here is the code I use when spawning my obstacles - I think it is where the problem is
func createRocks() {
rockHeight = (frame.height * (heightOfRocks))
if gameState != .Dead {
switch spawnCount {
case 10:
levelUp()
case 20:
levelUp()
case 30:
levelUp()
case 40:
levelUp()
case 50:
levelUp()
case 60:
levelUp()
case 70:
levelUp()
case 80:
levelUp()
case 90:
levelUp()
case 100:
levelUp()
case 110:
levelUp()
case 120:
levelUp()
case 130:
levelUp()
case 140:
levelUp()
case 150:
levelUp()
default:
break
}
}
++spawnCount
let leftRock = SKShapeNode(rectOfSize: CGSize(width: (frame.width), height: (rockHeight)), cornerRadius: (cornerRad))
leftRock.fillColor = themeColor
leftRock.strokeColor = themeBorderColor
leftRock.lineWidth = themeBorderWidth
leftRock.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: ((frame.width) + (themeBorderWidth)), height: ((rockHeight) + (themeBorderWidth))))
leftRock.physicsBody?.dynamic = false
let rightRock = SKShapeNode(rectOfSize: CGSize(width: (frame.width), height: (rockHeight)), cornerRadius: (cornerRad))
rightRock.fillColor = themeColor
rightRock.strokeColor = themeBorderColor
rightRock.lineWidth = (themeBorderWidth)
rightRock.physicsBody = SKPhysicsBody(rectangleOfSize: CGSize(width: ((frame.width) + (themeBorderWidth)), height: ((rockHeight) + (themeBorderWidth))))
rightRock.physicsBody?.dynamic = false
leftRock.zPosition = CGFloat(10 + (21 * levelNumber))
rightRock.zPosition = CGFloat(10 + (21 * levelNumber))
// 2
let rockCollision = SKSpriteNode(color: UIColor.clearColor(), size: CGSize(width: (frame.width * 2), height: 32))
rockCollision.physicsBody = SKPhysicsBody(rectangleOfSize: rockCollision.size)
rockCollision.physicsBody?.dynamic = false
rockCollision.name = "scoreDetect"
addChild(leftRock)
addChild(rightRock)
addChild(rockCollision)
// 3
let rockWidth = frame.width
let yPosition = frame.height + leftRock.frame.height
let rockDistance = frame.width * (gapWidth)
let min = Int(((frame.width) * (wallWidth)) - (rockWidth / 2))
let max = Int(((frame.width) * (1.00 - ((wallWidth)))) - rockDistance - (rockWidth / 2))
let rand = min + Int(arc4random_uniform(UInt32(max - min)))
//GKRandomDistribution(lowestValue: min, highestValue: max)
let xPosition = CGFloat(rand)
// 4
leftRock.position = CGPoint(x: xPosition, y: yPosition)
rightRock.position = CGPoint(x: xPosition + rockWidth + rockDistance, y: yPosition)
rockCollision.position = CGPoint(x: xPosition, y: CGRectGetMidY(frame))
rockCollision.position = CGPoint(x: CGRectGetMidX(frame), y: yPosition + (rockCollision.size.height * 2))
let endPosition = frame.height + (leftRock.frame.height * 2)
let moveAction = SKAction.moveByX(0, y: -endPosition, duration: timeOfRockMovement)
let moveSequence = SKAction.sequence([moveAction, SKAction.removeFromParent()])
leftRock.runAction(moveSequence)
rightRock.runAction(moveSequence)
rockCollision.runAction(moveSequence)
}
func initRocks() {
let create = SKAction.runBlock { [unowned self] in
self.createRocks()
}
let wait = SKAction.waitForDuration(rockSpawnWait)
let sequence = SKAction.sequence([create, wait])
let repeatForever = SKAction.repeatActionForever(sequence)
runAction(repeatForever)
}
Your approach sounds very similar to a SpriteKit tutorial I wrote, but I had no lag at all there. SpriteKit is awfully fast, but it's possible your exact conditions are causing problems. Things to check:
1) Are you using texture atlases? These are faster to load than separate images in your bundle.
2) If you're re-using images a lot, can you store them in an SKTexture then load your nodes from there?
3) Are there other things happening, such as sounds playing? The iOS Simulator frequently has a brief lag when it plays its first sound in a game.
4) Is the path that gets created very complicated?

in LUA....Corona SDK... My new score is Overlapping without erasing old score?

in code below it displays "SCORE: 100" or whatever however as the score / points change
the totals are over lapping one on top of the other and you cant read them ...
i want the old score erased / removed before displaying new score/points
ANY THOUGHTS HOW TO FIX this...this is LUA and using CORONA SDK
during my test i have sent print statements to try to troubleshoot sections
--Points is being calculated in another location
--UPDATE SCORE POINTS
local function updateScore(Points)
if WTF == 1 then
print ("SCORE: -->",Points)
--PointsText:removeSelf(PointsText)
PointsText = display.newText(Points,0,0,native.sytemFont,42)
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end
end
Every time you call updateScore you're creating a new text object. This code ensures you only create the text once.
local function updateScore(Points)
if PointsText == nil then
PointsText = display.newText(Points,0,0,native.sytemFont,42)
end
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end
You could also do:
local function updateScore(Points)
if PointsText then
PointsText:removeSelf()
end
PointsText = display.newText(Points,0,0,native.systemFont,42)
PointsText.text = Points
PointsText.xscale = 0.5; PointsText.yscale = 0.5
PointsText:setTextColor(155,155,225)
PointsText.x = centerX * 1
PointsText.y = centerY - 150
ScoreTxt = display.newText("Score: ",0,0,native.systemFont,40)
ScoreTxt:setTextColor(220,50,50)
ScoreTxt.x = display.contentCenterX
ScoreTxt.y = display.contentCenterY-100
end

Unclassifiable Statement at (1), Fortran90 error

I keep getting this error when I try to compile. I am not quite sure what the issue is. I am not the best at coding, and thus, debugging is not my strong suit. Any ideas whats causing the error?
PROGRAM Atmospheric_Reflection
IMPLICIT NONE
REAL*8:: Wavelength = 0.200D-6, WaveNumber = 0.0, pi = 3.14159265, Length(1:71) = 0, Number(1:71) = 0, IndexOfRe(1:71) = 0
INTEGER:: i = 0
!Calculate the wave number for wavelengths varying from 0.2 micrometers to 1.6 micrometers in increments of 0.02 micrometers
i = 1
DO WHILE (Wavelength <= 1.600D-6)
WaveNumber = 1/Wavelength
Length(i) = Wavelength
Number(i) = WaveNumber
IndexOfRe(i) = 1 + (((5791817.0/(238.0185 - WaveNumber**2))+(167909.0/(57.362-WaveNumber**2))))D-8
Wavelength = Wavelength + 0.02D-6
i = i+1
END DO
END PROGRAM
Possibly the D-8 at the end of this line
IndexOfRe(i) = 1 + (((5791817.0/(238.0185 - WaveNumber**2))+(167909.0/(57.362-WaveNumber**2))))D-8

Resources