Modifying the size in .as breaks 1 part of my game

Monkey Targets Forums/Flash/Modifying the size in .as breaks 1 part of my game

Fryman(Posted 2014) [#1]
I have this weird bug where if i change the size of the game in the MonkeyGame.as file, the life bars for player 2 stop drawing..

They work if I dont modify the size and everything else in the game draws and works correctly including the player1 bars which use the same code

The black background box draws but the green bars do not

Bars are called here
DrawEnergyBar(120, 60, Player2Life, 0, 2) 'Draw player 2 life bar
DrawEnergyBar(120, 25, Player2Energy, 1, 2) 'Draw player 2 life bar
DrawEnergyBar(360, 722, Player1Life, 0, 1) 'Draw Player 1 Life bar
DrawEnergyBar(360, 752, Player1Energy, 1, 1) 'Draw Player 1 Life bar


Bars are drawn here
Method DrawEnergyBar(X:int, Y:int, EnergyCurrent, Colour:int, Player:int)
	If Player = 1 Then
			SetColor(0, 0, 0)
			DrawRect(X, Y, 100, 20)
			If Colour = 0 Then SetColor(55, 255, 24)
			If Colour = 1 Then SetColor(11, 171, 0)
			DrawRect(X + 1, Y + 1, EnergyCurrent - 2, 18)
			SetColor(255, 255, 255)
	Else
			SetColor(0, 0, 0)
			DrawRect(X - 100, Y, 100, 20)
			SetColor(55, 255, 24)
			If Colour = 0 Then SetColor(55, 255, 24)
			If Colour = 1 Then SetColor(11, 171, 0)
			DrawRect(X + 1, Y + 1, -EnergyCurrent - 2, 18)
			SetColor(255, 255, 255)
	End



Salmakis(Posted 2014) [#2]
Im not sure, but i see a difference, you use x-100 for the rect for player2 but you use x+1 for the "bar"
maybe it is just outside the screen or something?

DrawRect(X - 100, Y, 100, 20)
VS
DrawRect(X + 1, Y + 1, -EnergyCurrent - 2, 18)
so if the black rect is on border of your screen, then it may happen that your bar is outside of the screen? (100 pixels more right?)

edit:
oh ok nvm that, seems like you just draw this bar from the other side (like in an BeatEmUp game)
hmm so then i see no problem with the code for now


Fryman(Posted 2014) [#3]
Solved the issue by changing the way I draw the bars (No longer drawing them backwards)
perhaps it doesn't like the negatives on the drawrect function.

The weirdest part is still it that it worked perfectly until I changed the size in the .AS file no other changes
	
	Method DrawEnergyBar(X:int, Y:int, EnergyCurrent, Colour:int, Player:int)
	If Player = 1 Then
			SetColor(0, 0, 0)
			DrawRect(X, Y, 100, 20)
			If Colour = 0 Then SetColor(55, 255, 24)
			If Colour = 1 Then SetColor(11, 171, 0)
			DrawRect(X + 1, Y + 1, EnergyCurrent - 2, 18)
			SetColor(255, 255, 255)
	Else
			SetColor(0, 0, 0)
			DrawRect(X - 100, Y, 100, 20)
			SetColor(55, 255, 24)
			If Colour = 0 Then SetColor(55, 255, 24)
			If Colour = 1 Then SetColor(11, 171, 0)
			DrawRect( (X + 120 - (X + EnergyCurrent)), Y + 1, (EnergyCurrent) - 2, 18)
			'DrawRect(X + 1, Y + 1, -EnergyCurrent - 2, 18)
	
			SetColor(255, 255, 255)
	End



golomp(Posted 2014) [#4]
Personnally i dont use at all the .as file. When i make a flash game i only upload the swf file and make a link on it as an embended file. Do i do wrong ?


Fryman(Posted 2014) [#5]
Not really however my game was written for a tablet and runs in portrait mode with some screen scaling going on for the different screen sizes, If the size isnt changed in the .as file the game ends up having black borders.

I probably should of targeted the scaling at just mobile devices however editing 1 line vs adding 10 or so, was a lazy / easy choice especially considering flash was a secondary target


golomp(Posted 2014) [#6]
ok, sorry i didn't thought about that case.