Constrain Attribute Alternatives

micmamicma Member Posts: 66
edited August 2014 in Working with GS (Mac)

Hey GS Community!
I am creating an endless runner with a custom display for the score. (What I mean by custom display is a score display using images of numbers I have created myself). The code looks like this:
Constrain Attribute: self.Image To: floor(game.score%self.div)/(self.div/10)

The self.div is basically the place of the number*10
So the Ones place's div is 10
10's place is 100
etc..

Every time the score goes to update (every 0.5 seconds), the game has a sudden (but only momentary) lag spike.
I'm pretty sure this is caused by the constraining of the score, but I don't know of any other alternatives to constraining. (Maybe looping, but I am still not very good at using GameSalad's loop feature)

Any Suggestions will be much appreciated :)

Thanks,
Micma

Edit: The game is currently only 7.9 MB in the Creator.

Comments

  • SocksSocks London, UK.Member Posts: 12,822

    @micma said:
    I'm pretty sure this is caused by the constraining of the score . . .

    I'd first establish for certain whether this is causing the issue. You can switch off the Constrain behaviour by clicking on the little 'on' button, if the 'lag spike™' still happens you know it's not the constrain behaviour, if it stops then it is likely being caused by the constrain behaviour.

    @micma said:
    but I don't know of any other alternatives to constraining

    The Change Attribute behaviour should work.

  • micmamicma Member Posts: 66

    I have now checked and it is for sure the constrain attribute function.

    @Socks said:
    The Change Attribute behaviour should work.

    I just tried this and it is still there.

    Good suggestion though.

  • SocksSocks London, UK.Member Posts: 12,822

    @micma said:
    I have now checked and it is for sure the constrain attribute function.

    So, we definitely know it's the Constrain behaviour that is causing the issue.

    @micma said:
    I just tried this and it is still there.

    Ok, so you changed the Constrain Attribute behaviour for a Change Attribute behaviour and the problem remains, yet you are sure it is caused by the Constrain Attribute behaviour ?

  • micmamicma Member Posts: 66

    Ok. Basically it is narrowed down to "I know that it is being caused by the updating of the score." It is the same whether it is constrain or change (every 0.5 seconds)... Would changing the images to .png be any more helpful, or maybe making them a lower res? right now they are 500 ppi (Same as everything else in my game... for the most part).

  • pHghostpHghost London, UKMember Posts: 2,342

    Hmm...one thing I don't understand. You say you are using constrain, but at the same time, the score updates only every 0.5 seconds? How is that. Constrain doesn't/shouldn't have a interval like that, it is updating with every frame.

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2014

    @micma said:
    Ok. Basically it is narrowed down to "I know that it is being caused by the updating of the score."

    Yep, makes sense, sounds like it's a general issue to do with how you have the score working.

    @micma said:
    It is the same whether it is constrain or change (every 0.5 seconds)... Would changing the images to .png be any more helpful . . . .

    Any more helpful than what ?

    @micma said:
    or maybe making them a lower res? right now they are 500 ppi (Same as everything else in my game... for the most part).

    A resolution value is meaningless by itself, a 8,000ppi file could be tiny while a 7ppi file could be enormous - 500ppi doesn't say anything other than how many pixels are in each inch. A bit like describing a street by saying there is a car every 4 metres (4cpm) and then asking someone to tell you how many cars are in the street using only this information ! :smile:

  • micmamicma Member Posts: 66

    @pHghost said:
    Hmm...one thing I don't understand. You say you are using constrain, but at the same time, the score updates only every 0.5 seconds? How is that. Constrain doesn't/shouldn't have a interval like that, it is updating with every frame.

    1 point is added to the attribute game.score every 0.5 seconds... but my custom font numbers are constrained... hence they are going to change every 0.5 seconds.

  • micmamicma Member Posts: 66

    @Socks said:
    A resolution value is meaningless by itself, a 8,000ppi file could be tiny while a 7ppi file could be enormous - 500ppi doesn't say anything other than how many pixels are in each inch. A bit like describing a street by saying there is a car every 4 metres (4cpm) and then asking someone to tell you how many cars are in the street using only this information ! :smile:

    What I mean by telling you the ppi is that I'm thinking that maybe because the image is a higher resolution, the file size is larger and is thus causing the game to slow down.

  • pHghostpHghost London, UKMember Posts: 2,342

    @micma‌ -- but you don't measure resolution of an image on screen by ppi, simply by pixels. What are the pixel dimensions of your images?

  • micmamicma Member Posts: 66

    @pHghost‌ 31x29

  • pHghostpHghost London, UKMember Posts: 2,342

    That's tiny. Definitely not higher resolution.

    You shouldn't be having problems due to size with those. They will be around 2kb in size each, right?

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2014

    @pHghost said:
    1 point is added to the attribute game.score every 0.5 seconds...

    This is going off topic a little, not related to your main question, but . . .

    I'm a great believer in efficiency, keeping things as simple and as stripped down as possible, here self.time (or game.time) is directly related to game.score, game.score is twice the value of self.time - so I'd be tempted to just use self.time/2 instead of having an additional attribute (game.score) and the rules and timers to make it track self.time . . . .

    You could dump all that unnecessary intermediate stuff and just have:

    floor((self.time/2)%self.div)/(self.div/10)

  • micmamicma Member Posts: 66

    The actual file sizes are 244x313. They are just scaled way down to fit into the small space of an iPhone. The file sizes are around 25kb each.

  • pHghostpHghost London, UKMember Posts: 2,342

    So wait, the image resolution is 244x313 pixels, but it is on a 29x31 size actor? Is that correct? That would definitely be asking more memory than if you optimize it.

    Always aim to have the image file exactly 2x the size of the actor, if you are publishing for Apple retina devices, for the most optimized performance.

  • SocksSocks London, UK.Member Posts: 12,822

    @micma said:
    What I mean by telling you the ppi is that I'm thinking that maybe because the image is a higher resolution . . .

    Higher than what ? Like I say resolution, by itself, doesn't say anything useful.

    @micma said:
    the file size is larger . . .

    Larger than what ? All these things, 'larger' or 'ppi' or 'is PNG more helpful' . . . keep inviting (for me at least) a 'larger than what', 'higher than what', 'is PNG more helpful than what' . . . and so on.

    Maybe I'm not the right person for these kinds of questions, I need cold hard facts ! :smiley: For example 'I am using XXXX, would YYYY be better?' rather than 'would YYYY be better?', to which I can only say would YYYY be better than what ?

    Good luck with the issue, hope you sort it out.

  • pHghostpHghost London, UKMember Posts: 2,342

    @Socks‌ -- that would only work if it was adding a point every 0.5 seconds of the full runtime, but if you have menus, etc. it wouldn't really be practical, right? Or is there an optimal way to use game.time in those situations?

  • micmamicma Member Posts: 66

    @pHghost said:
    So wait, the image resolution is 244x313 pixels, but it is on a 29x31 size actor? Is that correct? That would definitely be asking more memory than if you optimize it.

    Always aim to have the image file exactly 2x the size of the actor, if you are publishing for Apple retina devices, for the most optimized performance.

    Ok I will try this out. It makes sense.

  • micmamicma Member Posts: 66

    @Socks Haha! I get what you are saying. I will definitely let you know if I get more definite facts. Thanks for your help though!

  • SocksSocks London, UK.Member Posts: 12,822
    edited August 2014

    @pHghost said:
    Socks‌ -- that would only work if it was adding a point every 0.5 seconds of the full runtime, but if you have menus, etc. it wouldn't really be practical, right?

    All things being equal . . . .

    If the idea of using self.time (or game.time) directly would fail due to menu use (and so on), then the current system would fail due to menu use (and so on) as it directly tracks self.time (or game.time) - they are, as described ('1 point is added to the attribute game.score every 0.5 seconds...'), essentially the same thing, the same value scale (albeit one is always twice as large as the other), going up at the same rate.

    @pHghost said:
    Or is there an optimal way to use game.time in those situations?

    Not 100% sure what that means !?

  • pHghostpHghost London, UKMember Posts: 2,342

    @micma said:
    Ok I will try this out. It makes sense.

    Did it help?

  • micmamicma Member Posts: 66

    @pHghost said:
    Did it help?

    I ended up just having to use one of GS's fonts in a display text function. The game I was talking about is actually being submitted to apple right now. Thanks for the help!

Sign In or Register to comment.