onaluf / gameQuery

a javascript game engine with jQuery
http://gamequeryjs.com
633 stars 161 forks source link

Latest Commit made setAnimation() fails. #3

Closed Elyx0 closed 12 years ago

Elyx0 commented 13 years ago

setAnimation does not change the background-image anymore. (But works fine on the stable Version 0.5.1.

Elyx0 commented 13 years ago

(And neglect the offsets settings)

Elyx0 commented 13 years ago

Found a workaround.

Line 209-225:

                        // update the background:
                        if(gameQuery.animation.type & $.gameQuery.ANIMATION_VERTICAL){
                            if(gameQuery.multi){
                                $(this).css("background-position",""+(-gameQuery.animation.offsetx-gameQuery.multi)+"px "+(-gameQuery.animation.offsety-gameQuery.animation.delta*gameQuery.currentFrame)+"px");
                            } else {
                                $(this).css("background-image","url('"+gameQuery.animation.imageURL+"')");
                                $(this).css("background-position",""+(-gameQuery.animation.offsetx)+"px "+(-gameQuery.animation.offsety-gameQuery.animation.delta*gameQuery.currentFrame)+"px");
                            }
                        } else if(gameQuery.animation.type & $.gameQuery.ANIMATION_HORIZONTAL) {
                            if(gameQuery.multi){
                                $(this).css("background-image","url('"+gameQuery.animation.imageURL+"')");
                                $(this).css("background-position",""+(-gameQuery.animation.offsetx-gameQuery.animation.delta*gameQuery.currentFrame)+"px "+(-gameQuery.animation.offsety-gameQuery.multi)+"px");
                            } else {
                                $(this).css("background-image","url('"+gameQuery.animation.imageURL+"')");
                                $(this).css("background-position",""+(-gameQuery.animation.offsetx-gameQuery.animation.delta*gameQuery.currentFrame)+"px "+(-gameQuery.animation.offsety)+"px");
                            }
                        }
FostUK commented 12 years ago

Tested this and it appears to work. Have added to my fork and issued a pull request.

FostUK commented 12 years ago

This appears to have been because I had default CSS background images (handy and more efficient in some cases) and was assigning animations with a blank 'imageURL' property. This assigns the inline style background-image:url(''); which breaks everything after it. Even though clearly an error it's actually hard to debug because the above doesn't show in webkit web inspector on the element. Possibly could be the same error Elyx0 is experiencing.

Added minor alterations to code which only assign background-image if imageURL is present. Prevents similar errors and add versatility of assigning background-image via a css class if needed and overriding on a per animation basis. Pull request sent.

onaluf commented 12 years ago

Ok then I will close the issue since I've merged you code. If Elyx0 is still following this issue and that the solution doesn't solve his problem he is welcomed to re-open it!