I'm making a Space Invaders Clone. Yes, thank you, it's very original, i know :)
Im my Update() i restrict the player (the image of the player) to remain inside the screen. Now because i dont want half the ship to be offscreen i make a margin on x with the width of the player image.
What i'm wondering is, is every call of Update() going to recalculate the width of the image and if so, should i define it once as a constant variable in the constructor of the player to save cpu-time or does the compiler optimize these kind of recuring calculations for me?
Im my Update() i restrict the player (the image of the player) to remain inside the screen. Now because i dont want half the ship to be offscreen i make a margin on x with the width of the player image.
What i'm wondering is, is every call of Update() going to recalculate the width of the image and if so, should i define it once as a constant variable in the constructor of the player to save cpu-time or does the compiler optimize these kind of recuring calculations for me?
Type TPlayer Extends TGameObject Function Create:TPlayer(px:Int, py:Int, pspeed:Int, pimg:String) Local P:TPlayer = New TPlayer P.x = px P.y = py P.speed = pspeed P.img = LoadImage(pimg) ListAddLast GameObjectList, P Return P End Function Method Update() If Self.x < ImageWidth(Self.img)/2 ; x = ImageWidth(Self.img)/2 If Self.x > ScreenWidth - (ImageWidth(Self.img)/2); x = ScreenWidth - (ImageWidth(Self.img)/2) End Method End Type