Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Difficult question about nextlevel and change images

$
0
0

Hello, this part of my code. I have a problem, with change image. When I win level and I click back to menu with levels, the image is change on this level. But when I win first level than I click "next level", and I win second level, than I go to menu with levels, and the image first's level is change, but image second's level isn't change - it is a problem. When I close game and open it - the images of levels ara change(it is excellent). Problem with button next level. Help me please.

function createRow(i) {
 
        if(!Ti.App.Properties.hasProperty(i)) { 
            Ti.App.Properties.setString(i, 'lamp0.png');
        }
 
 
        var row = Ti.UI.createView({
            backgroundColor: 'white',
            borderColor: '#bbb',
            borderWidth: 1,
            width:'33.33%', height: 90,
            top: 0, left: 0,
            level: i
        });
        var levelsImg = Ti.UI.createImageView({
            image : Ti.App.Properties.getString(i), // this image I need change.
            keyboardType: Ti.UI.KEYBOARD_NUMBERS_PUNCTUATION,
            top: 10, left: '10%',
            width: '80%', height: 'auto'
        });
        row.add(levelsImg);
 
        row.addEventListener('click', function(){
            levelfunc(i);
        });
            function levelfunc(i){
                var winGame = Ti.UI.createWindow({
                    backgroundColor:'white'
                });
 
                ////// GAME/////////////////////
        answerButton.addEventListener('click', function(e){
 
                    var alertDial = Ti.UI.createAlertDialog({
                        title : "You win!", 
                        buttonNames: ["cancel", "levels", "nextlevel"], 
                        cancel: 0
                    });
 
                    alertDial.addEventListener('click', function(e){
                        if (e.index == 1){
                            winGame.close();
                        } else if (e.index == 2){ // button next level
                            winGame.close();
                            levelfunc(i+1);
                        }
                    });
                    if (firstAnswer == data[i].answer){
                        levelsImg.image = 'lamp1.png'; // change image for level wich I chose and win, but does not change for next win's levels.
                        Ti.App.Properties.setString(i, 'lamp1.png'); // change image - it's work, when I close game.
                        alertDial.show();
 
                    }
 
                });
 
                var buttonLevels = Titanium.UI.createButton({
                    title:'Close',
                    width:200,
                    height:40,
                    bottom: "5%"
                });
                winGame.add(buttonLevels);
                buttonLevels.addEventListener('click',function(){
                    winGame.close();
                });
                winGame.open();
            }
 
 
        return row;
    }
 
    var scrollView = Ti.UI.createScrollView({
        top:70,
        contentHeight: 'auto',
        showVerticalScrollIndicator:true,
        contentWidth:Ti.Platform.displayCaps.platformWidth,
        layout: 'horizontal'
    });
 
    for(var i = 0; i < 36; i++){
        var row = createRow(i);
        scrollView.add(row);
 
    }
    winLevels.add(scrollView);
 
    var label = Ti.UI.createLabel({
        text: 'Levels',
        textAlign: 'center',
        top:0,
        width: Titanium.UI.FILL, height:50
    });
    winLevels.add(label);
 
 
    var buttonMenu = Titanium.UI.createButton({
        title:'Close',
        width:200,
        height:40,
        bottom: "5%"
    });
    winLevels.add(buttonMenu);
    buttonMenu.addEventListener('click',function()
    {
        winLevels.close();
    });
    winLevels.open();
});
P.S. Sorry for my English :-).

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>