Saving files to server in Cocos2d Javascript Game - php

I've been struggling with this for a while and eventually gave up on inpementing any sort of savegame option client side with my cocos2d javascript game (structure based on this tutorial http://www.raywenderlich.com/33028/how-to-make-a-cross-platform-game-with-cocos2d-javascript-tutorial-the-platforms .. thx Ray .. )
Now i'm trying to find a way to save xml files to a webserver while running my game, firstly in a browser (because that seems the most straightforward way to get this going) and then hopefully later as an app that can access that same webserver.
I have a fair idea how to generate the xml from my array objects and I realise php is my friend when it comes to writing that xml file to disk on the server side. I've even heard of his pal AJAX that seems to have his contact details : )
My biggest problem at the moment is that the AJAX exampes I have found all use jquery. I realise this might be to simplify the cross browser compatibility issues but I can't fiure out how to add JQuery functionality to the JS in my game (probably stupidly basic or impossible as it will mess up all the bindings, I don't know). Most examples assume were doing all this straight form a browser script so any help with that would be great.
If jquery is a no go , does anyone have and example of how to send xml data in any format to php?
I'm sure there are enough tutorials out there on how to hande things from there...
If there is a simpler or better way to save savegames locally or on a server using the cocos2d javascript idea i'd be happy to hear it.
Thx..
Edit
I have managed to figure out that the simple answer to the jquery option (at least when deploying to web) is to include jquery at the top of the cocos2d.js file where all the other js files are loaded... might not be a sound option when it comes to porting it all to iphone though.

sys.localstorage is the way to save data.

Related

Can a website exist without HTML?

I previously had someone build a website for me. It was 90% finished but then ill health got in the way.
I have all the files and I am now asking people to "put the website back together for me". The general consensus is that it's very messy and not clear what was done and some of the protocols are now out of date etc. And it would just be better to start from scratch. I have heard this from multiple people.
So now when I am asking a new guy to build it from scratch, he is asking me for the HTML files. I couldn't see any, so I contacted the previous developer and he said:
There are no HTML files, it all runs through the index.php file and
extracts pages, data etc. from the database.
I told this to the new developer, but he is saying:
But website is not possible without HTML. Ask him provide index HTML.
Pure HTML without php code.
I'm confused, because I saw the website up and running, so it seems it is possible without HTML?
I'm trying to figure out where the misunderstanding is happening.
Thanks.
What your previous developer is saying is that your site was dynamic and all requests were flowing through your index.php file, which in turn does some backend logic to produce HTML data for the browser to interpret. If you ask your previous developer to zip up the root of your old site, your new developer should be able to take it from there.
Can a website exist without HTML?
Without a .html file? Yes. Using only .php, .css and .js is possible.
Without using Hyper Text Mark-up Language? No. There ar no other mark-up language for browsers, afaik. So we're stuck with this.
Old dev used PHP for efficiency. Contents are in your database and fetched using php to show up in browser.
New dev probably only knows HTML and has no clue about php. Or, probably doesn't want to bother reading through the php codes to reverse engineer how your site works.
Suggestion: Get a different dev. A smarter one. You probably have to pay more, but it's more expensive to hire a less smarter dev.

PhoneGap: use PHP to create the HTML?

I want to make apps for iPhone and Android, but as an enthusiastic PHP-programmer, I'm not really willing to learn Java or C++. So I ran into PhoneGap.
BUT... I don't really like programming in pure HTML and Javascript either! (all those hooks, commas in JQuery etc. are just too messy, in my opinion...and I hate CSS too).
The way I use PHP now, is that I have written a quite advanced framework, that processes clean xml-templates into HTML/Javascript. This way I can make my own custom HTML-tags, that do all the work of CSS, extra HTML and it creates all Javascript for me automatically...
It's a bit how Delphi for PHP and Prado work. Once the (visual!) PHP-components are done, I can use them over and over again... and only have to think about HTML, CSS and Javascript once, while building the component...
Okay, now my question: since I can't use PHP on the client with PhoneGap, but DO need the HTML, would it be a crazy idea to let my web-server create the HTML for me the first time the app runs, then store the HTML locally using PhoneGap, and then the next time the app is loaded, reuse the locally stored HTML ?
So my question is : can I create HTML on a webserver, and then store that HTML locally so my PhoneGap-app can use that? Or is the HTML in a PhoneGap app somehow 'compiled' and cannot be changed afterwards ?
Or is this a really stupid idea and should I abandon my nice PHP-components framework? What are your thoughts?
It's hard to give a meaningful answer to a question like this without some context. The big question that you've left unanswered is: What are you really trying to do? What will the apps that you create do, and what will make yours different and better than apps that are already out there? Do you want to sell these apps in the app store? Are you trying to collect and/or disseminate mission-specific information for your company?
On the face of it, writing a bunch of HTML and PHP that'll execute on your server just to generate a bunch of HTML and JavaScript that'll execute in a PhoneGap application seems like a lot of trouble. OTOH, if that's what you're most comfortable with, and if you can get it to do what you want, go for it.
If you give your framework a catchy name and make some bold assertions about how it's the newest, fastest best way to develop mobile applications, you can probably turn it into a book deal. ;-) Until that happens though, you'll have a hard time finding answers to questions about writing iPhone apps using PHP.

Can PHP analyze another web page?

I'm making a search engine that (in theory) analyzes online encyclopedias to get answers to a user's question from a form. However, I want to know if I'm wasting my time with the PHP. If I am, what language would be best suited to this task? If I'm not, what function in PHP would allow me to do this? Thanks!
PHP works as well as anything else. If you want to read data off of another webpage, you'll probably want to use cURL, which is built in to PHP.
All of the requisite pieces are there: PHP does fine with processing text and HTML. If you already know PHP, it's best to stick with what you know.
This is easy enough to do with PHP. If the sites you are getting the data from are valid xhtml it will be extremely easy to process the page and extract the data using the simplexml extension.

Real time RSS display on web page (best practices and source codes)

i have a php script who parser a rss and give me the data in a know pattern. Im very new with ASP, JavaScript and Jquery so i dont have any idea of how to autoupdate the script and display the new data with a smooth animation (see this example, that exactly what i want). Thanks for the support and if you know a good script to made this i will appreciate it.
Seems like you're looking for this:
http://leftlogic.com/lounge/articles/jquery_spy2/
It's PHP (not ASP), so that might be an issue, though the code is SUPER easy to implement (I've written by own implementation on three separate occasions).
The site itself has some decent documentation on getting things up and running, but if you need some extra help, comment and I'll point you in the right direction :)
Good luck!
The resources people have linked here are helpful and merely mentioning jQuery means you're probably headed in the right direction. But if you're new to this it might still be worth mentioning some of the concepts you'll be looking to play with here.
First of all, you'll probably want to stick with one language on the client side and one on the server side. This means choosing either PHP or ASP -- this isn't clear from your question but I'll assume you're dealing with PHP since that's the language I use for this kind of thing. JavaScript + jQuery is the right choice for the browser (client) side of things.
Like Luca points out, you'll have to set up some JavaScript code that goes live on page load and "polls" the server at a set interval. In JavaScript you do this using something called XMLHttpRequest (or "XHR") and it's pretty complicated. You could use combination of jQuery and a library like the one Matt points to in his answer, or just jQuery -- sample code abounds but it's basically a loop with a function call and sleep timer.
That function call is going to be one of the more difficult parts if you're trying to emulate the Twitter World Cup site. But here's the basic idea: You need to populate a list using jQuery and a data standard like JSON. Since the RSS feed you'll be parsing is written in XML, you'll have to write a server side (PHP/ASP) script that fetches, parses and converts the feed to JSON. In PHP, this is best done through cURL (file_get_contents() if you're lazy), SimpleXML and json_encode(), respectively.
Your JavaScript should load the list based on JSON. To do this, and display any new items, what you'll do is load the JSON from the client (browser) side using a jQuery method like getJSON(). Then you spin through the array object and add any new items to the list by adding new <li> elements to the "DOM." The same jQuery code that does this can easily also do the cross dissolve with something like fadeIn().
It looks like the script on that example page has an Ajax request running every TOT seconds.
You could simply have your PHP script return the RSS data (in JSON format say) and let JavaScript parse it and generate some HTML with it.
If all of this doesn't make sense to you I advice reading a little about JavaScript and PHP... there's plenty of good books.

PHP/Flash advice

Looking to start a project that would require me to use Flash or Flex (I have not worked with either of these yet, yikes!!!). Flash would be the front end user interface that needs to display items pulled from a MySQL Database (I was thinking ajax via jQuery but open to suggestions). My question is, What would be the best approach for something like this?
High level
Flash calls to display image through ajax/php from Db
I don't know how to code the Flash part, any tutorials that kinda sound like what I'm doing? suggestions? thoughts? other ideas?
Side Note: The database table will contain text that describes the image being passed to flash, so I would like to display both the text and image.
Thanks for any advice/help,
--Phill
I'd recommend you try AMFPHP or ZendAMF. Both of these use AMF3 (which requires you to use Actionscript 3/FlashCS3+), and it is one of the quickest ways to get data into Flash.
You could also use php to generate an xml file and just request that url in Flash to load up the XML. You can also use ajax like you said, but it's probably going to be the slowest method open to you, unless you're working with very small data sets.
Regardless of the method you choose, I'd suggest you use Actionscript 3. It's much faster and if you use XML, it'll be a life saver.
Here's a tutorial about setting up flash to work with PHP & MySQL:
link

Categories